[R] Extracting Numeric Columns from Data Fram

Marc Schwartz marc_schwartz at me.com
Sat Feb 16 20:17:48 CET 2013


On Feb 16, 2013, at 12:15 PM, Barry DeCicco <bdecicco2001 at yahoo.com> wrote:

> 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


Something like the following should work. If your data frame is "DF":

  NewDF <- DF[, sapply(DF, is.numeric)]

Regards,

Marc Schwartz



More information about the R-help mailing list