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.

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.

References

Templ, M. and Kowarik, A. and Meindl, B. Statistical Disclosure Control for Micro-Data Using the R Package sdcMicro. Journal of Statistical Software, 67 (4), 1--36, 2015. doi:10.18637/jss.v067.i04

Templ, M. Statistical Disclosure Control for Microdata: Methods and Applications in R. Springer International Publishing, 287 pages, 2017. ISBN 978-3-319-50272-4. doi:10.1007/978-3-319-50272-4 doi:10.1007/978-3-319-50272-4

Author

Bernhard Meindl

Examples

## 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"))