R implementation of the SPSS
RECODE Function. xpssRecode recodes atomics or vectors of the format numeric, character or factor under the terms of recode specifications.
a (non-empty) data.frame or input data of class "xpssFrame".
atomic character or character vector with the names of the variabless to recode.
character string with recoding specifications: for more informations see details.
atomic character or character vector with the names of new variables.
The input of the recoding is a character string with the recoding procedure seperated with a semicolon and a optional else statement.
single data transformation:
rec = "1 = 99; else = test"
For a numeric vector transformation:
rec = "c(1,2,3) = 1; else = 11"
For a character vector transformation:
rec = "c('A','B') = 'AB'; c('C','D') = 'CD'; else = 'ZZ'"
For a range of values:
rec = "lo:10 = 1; 11:22 = 2; 23:hi = 3; else = 'copy'".
hi are special values and determine the lowest and highest value of a numeric variable.
":"-Operator differs in this context from the sequence operator. In xpssRecode it specifies the range from A to B.
F.e. 1:10 defines the range from 1 till 10, all values which are within this range get recoded.
else statement indicates the handling of the values which are not selected by the recoding statement, this statement matches all unspecified values, including missing values.
System default, if no else statement is given, is
| ||overwrites all unmatched values with the original value.|
| || overwrites all unmatched values in the new dataset with
| ||overwrites all unmatched values with Other, only possible for character values.|
| ||overwrites all unmatched values with 99, only possible for numeric values.|
varout determines whether a new variable with the recoded values should appended at the end of the dataset.
A xpssFrame with the recoded variables.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
data(fromXPSS) fromXPSS <- xpssRecode(fromXPSS, variables ="V1", rec="'Audi' = 'Porsche'; else= copy", varout = NULL) fromXPSS <- xpssRecode(fromXPSS, variables = c("V5","V7_2"), rec = "lo:50 =1; 51:200=2; 201:hi=3; else = copy", varout =c("V5_new","V7_new")) fromXPSS <- xpssRecode(fromXPSS, variables = c("V6_kl3","V7_2"), rec = "sysmis = 99", varout =c("V6_new","V7_new"))