[R] ignorable warnings of as.numeric: NAs introduced by coercion
Wolfram Fischer
wolfram at fischer-zim.ch
Wed Oct 17 10:26:35 CEST 2007
Warnings are a good thing and can help to find errors in data.
But with newer R versions I get more and more warnings
which I would like to suppress in defined circumstances.
In the manual of as.numeric() is noticed:
as.numeric(c("-.1"," 2.7 ","B")) # (-0.1, 2.7, NA) + warning
If I know that my data contains characters and if I would like
that they will be converted to NA: how I can turn off just this warning?
(I know I could do: options(warn=-1). But then I will miss all
other possibly necessary warnings.)
I would like to have an argument to as.numeric() like na.coerce=TRUE.
It would be especially helpful when converting factors to numbers by doing:
as.numeric( levels( x ) )[ x ]
What could I do?
Best regards - Wolfram
More information about the R-help
mailing list