[R] variable number of variables in data frames
Robert.Denham@dnr.qld.gov.au
Robert.Denham at dnr.qld.gov.au
Tue Jul 17 07:36:20 CEST 2001
> For example, if I know columns 1:4 are to be treated as factors, I can
> write
> dat <- matrix(c(2,1,1,1, 1,1,1,1), 2, 4)
> D <- as.data.frame(dat)
> # force all variables to be treated as binary
>.# regardless of the small data set
> D$V1 <- factor(D$V1, 1:2)
> D$V2 <- factor(D$V2, 1:2)
> D$V3 <- factor(D$V3, 1:2)
> D$V4 <- factor(D$V4, 1:2)
> But how do I do this in general? What I would like to say is something
> like
Why not just
for (i in my.factor.columns) {
# D$Vi <- factor(D$Vi, 1:my.nlevels[i])
D[,i]<- factor(D[,i], 1:my.nlevels[i])
}
Robert
************************************************************************
The information in this e-mail together with any attachments is
intended only for the person or entity to which it is addressed
and may contain confidential and/or privileged material.
Any form of review, disclosure, modification, distribution
and/or publication of this e-mail message is prohibited.
If you have received this message in error, you are asked to
inform the sender as quickly as possible and delete this message
and any copies of this message from your computer and/or your
computer system network.
************************************************************************
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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