sdcMicroObj-class
or factor
or data.frame
R/groupAndRename.R
groupAndRename.Rd
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)
object of class sdcMicroObj-class
name of the keyVariable to change
vector of levels before recoding
name of new level after recoding
logical, if TRUE missing values in the input variables are added to the level specified in argument after
.
the modified sdcMicroObj-class
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.
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
## 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"))