[R] Creating subsets with factors
Liaw, Andy
andy_liaw at merck.com
Wed Jan 9 16:38:19 CET 2002
[snipped...]
> I have not needed to use c(f1, f2) but it seems to me that
> Peter's example points out more a deficiency in c or the need
> for another binding function for this case (which can be done
> with factor(c(as.character(f1),as.character(f2))) depending
> on how NAs are handled.
More often than I'd like, I have to combine several related data frames
together. The following showed that the rbind method for data frames does
do a reasonable job:
# Suppose dat1 and dat2 are two data frames with same variables.
> dat1$ind <- factor(rep("dat1", nrow(dat1)))
> dat2$ind <- factor(rep("dat2", nrow(dat2)))
> dat <- rbind(dat1, dat2)
> levels(dat$ind)
[1] "dat1" "dat2"
> Frank Harrell
[more snipped...]
Andy
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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