Greetings - In trying to do a multiple correspondence analysis, I need to coerce a data frame such that each of its columns will be a factor. Can someone offer advice on how to make this happen? I've tried this:> logic.resources.f.df<-apply(logics.resources.df, 2, factor)but:> is.factor(logic.resources.f.df$interests)[1] FALSE I've also tried individually,> foo<-data.frame(c(factor(mediate), factor(morality)))but still,> is.factor(foo$mediate)[1] FALSE Thanks for any assistance. ---------------------------------------------------------------------- Andrew J Perrin - Ph.D. Candidate, UC Berkeley, Dept. of Sociology Chapel Hill, North Carolina, USA - http://demog.berkeley.edu/~aperrin aperrin at socrates.berkeley.edu - aperrin at igc.apc.org -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
2001-Mar-01 20:08 UTC
[R] How to coerce data frame elements into factors?
Andrew Perrin <aperrin at socrates.berkeley.edu> writes:> Greetings - > > In trying to do a multiple correspondence analysis, I need to coerce a > data frame such that each of its columns will be a factor. Can someone > offer advice on how to make this happen? I've tried this: > > > logic.resources.f.df<-apply(logics.resources.df, 2, factor) > > but: > > > is.factor(logic.resources.f.df$interests) > [1] FALSEapply will give you a vector or array, so you're doing is.factor(NULL)> > > I've also tried individually, > > > foo<-data.frame(c(factor(mediate), factor(morality)))> > is.factor(foo$mediate) > [1] FALSEWhat gives you the idea that that would have a component called "mediate"?> x<-1:0 > y<-0:1 > data.frame(c(factor(x),factor(y)))c.factor.x...factor.y.. 1 2 2 1 3 1 4 2 Try this:> d<-data.frame(a=0:1,b=1:0) > d<-as.data.frame(lapply(d,factor))-- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._