[R] conversion of a data.frame of numerics to a data.frame of factors
Patrick Giraudoux
patrick.giraudoux at univ-fcomte.fr
Sat Oct 9 16:20:11 CEST 2004
Hi,
I am trying to convert a data.frame of numerics (this could be a matrix as well in this case) into a data.frame of factors.
I did it in a way that is less than direct...
myforet2<-t(myforet)
for (i in 1:length(myforet2[1,])) {
if (i == 1)myforetfact<-list(as.factor(myforet2[,i]))
else myforetfact<-c(myforetfact,list(as.factor(myforet2[,i])))
}
myforetfact<-data.frame(myforetfact)
names(myforetfact)<-row.names(myforet)
Here again, I wonder if there are no easier way to go through.... (the loop is not "R" style, for the least). However, I cannot do
it otherway so far...
Cheers,
Patrick
More information about the R-help
mailing list