[R] RE: variable number of variables in data frames
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Tue Jul 17 12:23:04 CEST 2001
"Henrik Bengtsson" <henrikb at braju.com> writes:
> Kevin, you can treat data frames as matrices, i.e. you can do
>
> dat <- matrix(c(2,1,1,1, 1,1,1,1), 2, 4)
> D <- as.data.frame(dat)
> for (i in 1:ncol(D))
> D[,i] <- factor(D[,i], 1:2)
..
> > for (i in my.factor.columns) {
> > D$Vi <- factor(D$Vi, 1:my.nlevels[i])
> > }
Also,
> D[1:2]<-lapply(D[1:2],factor,levels=1:2)
> summary(D)
V1 V2 V3 V4
1:1 1:2 Min. :1 Min. :1
2:1 2:0 1st Qu.:1 1st Qu.:1
Median :1 Median :1
Mean :1 Mean :1
3rd Qu.:1 3rd Qu.:1
Max. :1 Max. :1
--
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list