[R] Unexpected behavior in recode{car}

From: D. Dailey <lists_at_compassroseenterprises.com>
Date: Thu 28 Jul 2005 - 13:44:38 EST

Thanks to the R creators for such a great statistical system. Thanks to the R help list, I have (finally) gotten far enough in R to have a question I hope to be worth posting.

I'm using the recode function from John Fox's car package and have encountered some unexpected behavior.

Consider the following example:

## Begin cut-and-paste example
require( car )
nn <- sample( c( 2, 4 ), size=50, replace=TRUE ) rr <- recode( nn, "2='TWO';4='FOUR'" )
table( rr, exclude=NULL )
ss <- recode( nn, "2='Num2';4='Num4'" ) # Doesn't work as expected table( ss, exclude=NULL )
tt <- recode( nn, "2='TWO'; 4='Num4'" )
table( tt, exclude=NULL )
uu <- recode( nn, "2='Num2'; 4='FOUR'" ) table( uu, exclude=NULL )
## End cut-and-paste example

All but the recoding to ss work as expected: I get a character vector with 23 instances of either "FOUR" or "Num4" and 27 instances of "TWO" or "Num2".

But for the ss line, wherein all the strings to be assigned contain a digit, the resulting vector contains all NAs. Using str(), I note that ss is a numeric vector.

Is there a tidy way (using recode) to recode numeric values into character strings, all of which contain a digit? I have a workaround for my current project, but it would be nice to be able to use mixed alphanumeric strings in this context.

Thanks in advance for any insight you can give into this question.

Using R 2.1.1 (downloaded binary) on Windows XP Pro, car version 1.0-17 (installed from CRAN via Windows GUI). Complete version information below:

> version

platform i386-pc-mingw32

arch     i386
os       mingw32

system i386, mingw32
major 2
minor 1.1
year 2005
month 06
day 20
language R

> t(t( installed.packages()['car',] ))


Package  "car"
LibPath  "C:/Programs/R/rw2011/library"
Version  "1.0-17"

Priority NA
Bundle NA
Contains NA
Depends "R (>= 1.9.0)"
Suggests "MASS, nnet, leaps"
Imports NA
Built "2.1.0"

I subscribe to the help list in digest form, so would appreciate being copied directly in addition to seeing responses sent to the list.

David Dailey
Shoreline, Washington, USA

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jul 28 13:50:59 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:34:06 EST