Check if data frame column is numeric
... and an addendum Hadley Wickham's plyR package attempts to redress these (nevertheless documented) apparent inconsistencies in the *apply family of functions by handling everything in a more consistent intuitive manner. You may wish to use those instead of the base R *apply functions. -- Bert Gunter Genentech -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Henrique Dallazuanna Sent: Tuesday, December 16, 2008 9:32 AM To: Mark Heckmann Cc: r-help at r-project.org Subject: Re: [R] Check if data frame column is numeric Try: sapply(df, is.numeric)
On Tue, Dec 16, 2008 at 1:25 PM, Mark Heckmann <mark.heckmann at gmx.de> wrote:
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
______________________________________________ R-help at 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.
Henrique Dallazuanna Curitiba-Parana-Brasil 250 25' 40" S 490 16' 22" O [[alternative HTML version deleted]]