Hi, set.seed(15) dat1<-data.frame(col1=rnorm(6),col2=rep(1:2,each=3),col3=rep(letters[1:3],2),col4=runif(6),col5=rep(LETTERS[3:5],2)) dat1[,sapply(dat1,class)!="factor"] # col1 col2 col4 #1 0.2588229 1 0.5090904 #2 1.8311207 1 0.7066286 #3 -0.3396186 1 0.8623137 #4 0.8971982 2 0.8417851 #5 0.4880163 2 0.4474437 #6 -1.2553858 2 0.9646670
#or dat1[,grep("numeric|integer",sapply(dat1,class))] # col1 col2 col4 #1 0.2588229 1 0.5090904 #2 1.8311207 1 0.7066286 #3 -0.3396186 1 0.8623137 #4 0.8971982 2 0.8417851 #5 0.4880163 2 0.4474437 #6 -1.2553858 2 0.9646670 A.K. ----- Original Message ----- From: Barry DeCicco <bdecicco2...@yahoo.com> To: "r-help@R-project.org" <r-help@r-project.org> Cc: Sent: Saturday, February 16, 2013 1:15 PM Subject: [R] Extracting Numeric Columns from Data Fram Hello, I've got a data frame with a mix of numeric, integer and factor columns. I'd like to pull out (or just operate only on) the numeric/integer columns. Every thing I've found in searches is about how to subset by rows, or how to operate assuming you have the column names. I'd like to pull by type. Thanks! Barry [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.