[R] reading in columns of a data set as factors
Faheem Mitha
faheem at email.unc.edu
Fri Apr 28 01:47:22 CEST 2000
Dear Dr. Kleiber,
Just to make sure I understand this. lapply acts on lists. In the line
below, are we regarding mydat[ ,1:66] as a list with 66 components? How
is lapply happy to regard this as a list? I have only the dimmest
understanding of how classes are inherited by subsets of objects, but
class(mydat[ ,1:66]) gives data.frame, and is a data frame also a list?
Faheem.
> mydat[,1:66] _ lapply(mydat[,1:66],as.facto
On Thu, 27 Apr 2000, Faheem Mitha wrote:
> Thanks, this was exactly what I was looking for. Specifically, the last
> line:
>
> > mydat[,1:66] _ lapply(mydat[,1:66],as.factor
>
> can be used the replace the loop I have, and is much faster. Didn't think
> of using lapply. Must get to know it better. Looks like a useful
> all-purpose function.
> Faheem.
>
> On Thu, 27 Apr 2000, Pierre Kleiber wrote:
>
> > Here's how I would go about it:
> >
> > > mydat <- as.data.frame(matrix(scan("input.dat"),byrow=T,ncol=99)
> > > names(mydat) _ c(paste("b",1:66,sep=""),paste("x",1:33,sep=""))
> > > mydat[,1:66] _ lapply(mydat[,1:66],as.factor)
>
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list