Learn R Programming

sdcMicro (version 5.0.2)

groupAndRename: Join levels of a variables in an object of class sdcMicroObj-class or factor or data.frame

Description

If the input is an object of class sdcMicroObj-class, the specified factor-variable is recoded into a factor with less levels and risk-measures are automatically recomputed.

Usage

groupAndRename(obj, var, before, after, addNA = FALSE)

Arguments

obj

object of class sdcMicroObj-class

var

name of the keyVariable to change

before

vector of levels before recoding

after

name of new level after recoding

addNA

logical, if TRUE missing values in the input variables are added to the level specified in argument after.

Value

the modified sdcMicroObj-class

Details

If the input is of class data.frame, the result is a data.frame with a modified column specified by var.

If the input is of class factor, the result is a factor with different levels.

Examples

Run this code
# NOT RUN {
## for objects of class sdcMicro:
data(testdata2)
testdata2$urbrur <- as.factor(testdata2$urbrur)
sdc <- createSdcObj(testdata2,
  keyVars=c('urbrur','roof','walls','water','electcon','relat','sex'),
  numVars=c('expend','income','savings'), w='sampling_weight')
sdc <- groupAndRename(sdc, var="urbrur", before=c("1","2"), after=c("1"))
# }

Run the code above in your browser using DataLab