[R] lapply() not converting columns to factors (no error message)
A Singh
Aditi.Singh at bristol.ac.uk
Mon Nov 16 13:42:09 CET 2009
Dear List,
I'm having a curious problem with lapply(). I've used it before to convert
a subset of columns in my dataframe, to factors, and its worked. But now,
on re-running the identical code as before it just doesn't convert the
columns into factors at all.
As far as I can see I've done nothing different, and its strange that it
shouldn't do the action.
Has anybody come across this before? Any input on this strange issue much
appreciated..
Hope I haven't missed something obvious.
Thanks a lot,
Aditi
(P.s.- I've tried converting columns one by one to factors this time, and
that works.
>P1L55<-factor(P1L55)
>levels(P1L55)
>[1] "0" "1"
Code:
prm<-read.table("P:\\..... .csv", header=T, ...sep=",", ...)
prmdf<-data.frame(prm)
prmdf[2:13]<-lapply(prmdf[2:13], factor) ## action performed, no error
message
##I tried to pick random columns and check
>levels(P1L55)
>NULL
>is.factor(P1L96)
>FALSE
----------------------
A Singh
Aditi.Singh at bristol.ac.uk
School of Biological Sciences
University of Bristol
More information about the R-help
mailing list