sdcMicro (version 4.1.0)

globalRecode: Global Recoding

Description

Global recoding

Usage

globalRecode(obj,...)#, column,breaks, labels, method="equidistant")

Arguments

obj
vector of class numeric or of class factor with integer labels for recoding or an object of class sdcMicroObj
column
which keyVar should be changed
...
see possible arguments below
breaks
either a numeric vector of cut points or number giving the number of intervals which x is to be cut into.
labels
labels for the levels of the resulting category. By default, labels are constructed using "(a,b]" interval notation. If labels = FALSE, simple integer codes are returned instead of a factor.
method
method equidistant for equal sized intervalls method logEqui for equal sized intervalls for log-transformed data method equalAmount for interval

Value

  • the modified sdcMicroObj or a factor, unless labels = FALSE which results in the mere integer level codes.

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.

See Also

cut

Examples

Run this code
data(free1)
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))
table(globalRecode(free1[,"AGE"], breaks=c(1,9,19,29,39,49,59,69,100)))
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="urbrur", breaks=5)

Run the code above in your browser using DataCamp Workspace