globalRecode {sdcMicro} | R Documentation |
Global Recoding
Description
Global recoding of variables
Usage
globalRecode(obj, ...)
Arguments
obj |
a numeric vector, a |
... |
see possible arguments below
|
Details
If a labels parameter is specified, its values are used to name the factor levels. If none is specified, the factor level labels are constructed.
Value
the modified sdcMicroObj-class
or a factor, unless labels = FALSE
which results in the mere integer level codes.
Note
globalRecode
can not be applied to vectors stored as factors from sdcMicro >= 4.7.0!
Author(s)
Matthias Templ and Bernhard Meindl
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
See Also
Examples
data(free1)
free1 <- as.data.frame(free1)
## application to a vector
head(globalRecode(free1$AGE, breaks=c(1,9,19,29,39,49,59,69,100), labels=1:8))
table(globalRecode(free1$AGE, breaks=c(1,9,19,29,39,49,59,69,100), labels=1:8))
## application to a data.frame
# automatic labels
table(globalRecode(free1, column="AGE", breaks=c(1,9,19,29,39,49,59,69,100))$AGE)
## calculation of brea-points using different algorithms
table(globalRecode(free1$AGE, breaks=6))
table(globalRecode(free1$AGE, breaks=6, method="logEqui"))
table(globalRecode(free1$AGE, breaks=6, method="equalAmount"))
## for objects of class sdcMicro:
data(testdata2)
sdc <- createSdcObj(testdata2,
keyVars=c('urbrur','roof','walls','water','electcon','relat','sex'),
numVars=c('expend','income','savings'), w='sampling_weight')
sdc <- globalRecode(sdc, column="water", breaks=3)
table(get.sdcMicroObj(sdc, type="manipKeyVars")$water)