[R] Extracting Numeric Columns from Data Fram

Henrik Pärn henrik.parn at ntnu.no
Sun Feb 17 12:41:11 CET 2013

Dear Barry,

I saw that you received several nice answers on how to 'pull out' numeric columns. You also wrote that an alternative could be to 'just operate only on' numerics. Here is one possibility:


# some dummy data
df <- data.frame(nonnum1 = letters[1:5], num1 = 1:5, nonnum2 = letters[6:10], num2 = rnorm(5)) 

# operate only on numeric variables
numcolwise(.fun = mean)(df)

# or only on 'discrete' variables (following the terminology on ?colwise)
catcolwise(.fun = toupper)(df)

Best regards,



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.




Henrik Pärn
Centre for Conservation Biology
Department of Biology
Norwegian University of Science and Technology
NO-7491 Trondheim

Office: +47 735 96084   
Mobile: +47 909 89 255
Fax: +47 735 96100

More information about the R-help mailing list