[R] Check if data frame column is numeric

Mark Heckmann mark.heckmann at gmx.de
Tue Dec 16 16:25:07 CET 2008


Hi R-users,

I want to apply a function to each column of a data frame that is numeric.
Thus I tried to check it for each column first: 

> apply(df, 2, function(x) is.numeric(x))

     A60       A64      A66a       A67       A71      A75a       A80
A85       A91       A95       A96       A97       A98       A99 
    FALSE     FALSE     FALSE     FALSE     FALSE     FALSE     FALSE
FALSE     FALSE     FALSE     FALSE     FALSE     FALSE     FALSE

I get only FALSE results although the variables are numeric. When I try the
following it works:

> is.numeric(df$A60)
[1] TRUE

What am I doing wrong?

TIA
Mark



More information about the R-help mailing list