[R] Translation of R code required
Barry Rowlingson
B.Rowlingson at lancaster.ac.uk
Fri Nov 3 19:38:38 CET 2006
Sarah Goslee wrote:
> Since this step works,
>
> mental$Rx <- factor(mental$Rx, levels=c("VS","IPS"))
>
> I think that some of the names are right, but perhaps that
> one is spelled differently (Centre vs centre, maybe, since
> R is case-sensitive?).
How do you know that step works? If the dataframe 'mental' doesnt have
an 'Rx' column then mental$Rx will be 'NULL', and the factor() function
will make a factor out of that...
> x=data.frame(foo=1:10)
so x is a data frame with one column, called 'foo'. Now lets make
levels from a non-existent column, 'bar':
> x$bar=factor(x$bar,levels=c('x','y'))
No complaints... But try printing 'x' now (by typing x at the command
line)... Ick!
Try things one line at a time and check the objects created or
modified are sensible.
Barry
More information about the R-help
mailing list