i'm trying to build a little summary table for the contents of a data frame. t<-sapply(macro, data.class) c<-sapply(macro, length) m<-sapply(macro, mean, na.rm=T, digits=2) cbind(type=t, n=c , mean=m) I want to drop the variables that are factors so I can include -max- and -min- in my table. -macro- contacts the data--how do I drop the variables according to their data.class thanks, michael foster ________________________________________________ E. Michael Foster (W) 814-865-1923 (Fax) 814-863-0000 After 7/1 Work: Professor of Maternal and Child Health School of Public Health University of North Carolina, Chapel Hill Rosenau Hall, CB# 7445 Chapel Hill, NC 27599-7445 Home: 309 Old Larkspur Way Chapel Hill, NC 27516 UNC School of Public Health--voted #2 SPH by . US News . Association of Hand-to-Fin Carp Fisherman . Iron Chef (not to be confused with the Iron Dukes!)
try this # to get only the factors macro.f <- macro[sapply(macro, is.factor)] to drop the factors macro.nf <- macro[sapply(macro, !is.factor)] # to get only numerics macro.n <- macro[sapply(macro, is.numeric)] and so on. I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: "E. Michael Foster" <foster at pop.psu.edu> To: <r-help at stat.math.ethz.ch> Sent: Friday, June 17, 2005 4:57 PM Subject: [R] drop elements of vector by class> i'm trying to build a little summary table for the contents of a > data frame. > > t<-sapply(macro, data.class) > c<-sapply(macro, length) > m<-sapply(macro, mean, na.rm=T, digits=2) > cbind(type=t, n=c , mean=m) > > I want to drop the variables that are factors so I can include -max- > and > -min- in my table. > -macro- contacts the data--how do I drop the variables according to > their > data.class > > thanks, > michael foster > > > > > ________________________________________________ > E. Michael Foster > (W) 814-865-1923 > (Fax) 814-863-0000 > > After 7/1 > > Work: > Professor of Maternal and Child Health > School of Public Health > University of North Carolina, Chapel Hill > Rosenau Hall, CB# 7445 > Chapel Hill, NC 27599-7445 > > Home: > 309 Old Larkspur Way > Chapel Hill, NC 27516 > > > UNC School of Public Health--voted #2 SPH by > . US News > . Association of Hand-to-Fin Carp Fisherman > . Iron Chef (not to be confused with the Iron Dukes!) > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
a <- data.frame(a = 1:2, b = c("a", "b"), c = I(c("a", "b"))) a <- a[ , !sapply(a, class) %in% "factor"] -----Original Message----- From: E. Michael Foster [mailto:foster at pop.psu.edu] Sent: Friday, June 17, 2005 10:58 AM To: r-help at stat.math.ethz.ch Subject: [R] drop elements of vector by class i'm trying to build a little summary table for the contents of a data frame. t<-sapply(macro, data.class) c<-sapply(macro, length) m<-sapply(macro, mean, na.rm=T, digits=2) cbind(type=t, n=c , mean=m) I want to drop the variables that are factors so I can include -max- and -min- in my table. -macro- contacts the data--how do I drop the variables according to their data.class thanks, michael foster ________________________________________________ E. Michael Foster (W) 814-865-1923 (Fax) 814-863-0000 After 7/1 Work: Professor of Maternal and Child Health School of Public Health University of North Carolina, Chapel Hill Rosenau Hall, CB# 7445 Chapel Hill, NC 27599-7445 Home: 309 Old Larkspur Way Chapel Hill, NC 27516 UNC School of Public Health--voted #2 SPH by . US News . Association of Hand-to-Fin Carp Fisherman . Iron Chef (not to be confused with the Iron Dukes!) ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html