[R] using as.numeric() without generating warning message

Gabor Grothendieck ggrothendieck at gmail.com
Sat Apr 10 02:04:42 CEST 2010


Try this:

suppressWarnings(as.numeric("A"))

On Fri, Apr 9, 2010 at 7:22 PM, Andrew Yee <yee at post.harvard.edu> wrote:
> I'm interested in testing whether or not a character string is numeric or
> not as follows:
>
> is.na(as.numeric('3')) # returns F
> is.na(as.numeric('A')) # I'd like this to return T without issuing a warning
> about NAs introduced by coercion.
>
> I guess you could suppress the warning with options(warn=-1), but I was
> wondering if there's an alternative.  Or perhaps an alternative that doesn't
> use as.numeric()?
>
> Thanks,
> Andrew
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list