[R] Extracting Numeric Columns from Data Fram

Phil Spector spector at stat.berkeley.edu
Sat Feb 16 20:19:07 CET 2013

Barry =
    Suppose your data frame is called "mydat".   Then something like

    mydat[,sapply(mydat,class) %in% c('numeric','integer')]

might do what you want.
                                                     - Phil

On Sat, 16 Feb 2013, Barry DeCicco 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
> 	[[alternative HTML version deleted]]

More information about the R-help mailing list