Dear Julie,

At 08:57 PM 12/6/2003 -0200, Julie Remold wrote:
Hi to all,

I am having a problem when using recode from the car package. I have
a variable that is char and when I use recode to create a new
variable that is supposed to be numeric I get a factor variable. Here
is the code I am using:

> FCI$PRE1 <- recode (PRE1RES, " c('C', 'c')=1 ; else = 0 ;
as.factor.result=FALSE ")

So, if I understand correctly the recode command, the line above
should  create FCI$PRE1 variable with 1 if PRE1RES is c and zero
otherwise. However, if I type

> FCI$PRE1[0]

I get as result:

factor(0)
Levels: 0 1

FCI$PRE1 is not a numeric variable, and I get instead a factor.
Recode seems to work fine as it correctly replaces the c's for 1 and
other results for 0, but the fact that the recoded variable is a
factor does not work for me.

Any suggestions on what I am doing wrong?

You're putting quotation marks around the argument is.factor.result as if it's part of the recode specifications. I believe that you want


FCI$PRE1 <- recode (PRE1RES, " c('C', 'c')=1 ; else = 0 ", as.factor.result=FALSE )

I hope that this helps,
 John

-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: [EMAIL PROTECTED]
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to