Category Recoding Issue with S-PLUS 6.x
January 23, 2003
------------------------------------------------------
We would like to use the Recode dialog three times to recode all
occurrences of
0+ thru 11 to 0
11+ thru 15 to 1
15+ thru 21 to 2
This simply does not result in the proper recode and no error message indicates the correct action. We contacted S-PLUS support about this problem and the discussion is summarized below.
------------------------------------------------------
It does not work to recode "0+ thru 11" to 0, however, it does work to recode "11+ thru 15" to 1 and "15+ thru 21" to 2. The
problem is that the levels appear as:
> levels(bank$EDUC2) [1] " 0+ thru 11" "11+ thru 15" "15+ thru 21"Notice the space before the 0 in " 0+ thru 11". The first level has a space at the beginning, but the current value when doing Data -> Recode does not ("0+ thru 11").
This is a bug in S-PLUS -- Data -> Recode does not work in some particular cases if data are in "binned" form (i.e., result from Create Categories).
You can work around this problem by taking that space out of the first level. Right-click on column EDUC2, select Properties, and change Factor Level " 0+ thru 11" to "0+ thru 11". The command for this (from the History log) is:
guiModify( "factor", Name = "bank$EDUC2",
Levels = "\"0+ thru 11\", \"11+ thru 15\", \"15+ thru 21\"")
You can then use Data -> Recode (3 times) to recode the values. The commands for this are:
SDF1 <- menuRecode(data = bank, variable = list("EDUC2"),
current.value = "0+ thru 11", new.value = "0")
SDF1 <- menuRecode(data = bank, variable = list("EDUC2"),
current.value = "11+ thru 15", new.value = "1")
SDF1 <- menuRecode(data = bank, variable = list("EDUC2"),
current.value = "15+ thru 21", new.value = "2")
Another work around is to use Data -> Create Categories on the factor variable BANK2 (3 times) to recode the values. The commands to do this are:
menuCreateCategories(xname = "bank", col = "EDUC2", numuse = "Binning", nbin = 5,
numby = "Range", factorlevels = "[6] 0+ thru 11", newlevel = "0", newcol = "EDUC2")
menuCreateCategories(xname = "bank", col = "EDUC2", numuse = "Binning", nbin = 5,
numby = "Range", factorlevels = "[1] 11+ thru 15", newlevel = "1", newcol = "EDUC2")
menuCreateCategories(xname = "bank", col = "EDUC2", numuse = "Binning", nbin = 5,
numby = "Range", factorlevels = "[4] 15+ thru 21", newlevel = "2", newcol = "EDUC2")