I generally prefer to code R so that I don't get warnings, but I don't know how to avoid getting a warning when using as.numeric
to convert a character vector.
For example:
x <- as.numeric(c("1", "2", "X"))
Will give me a warning because it introduced NAs by coercion. I want NAs introduced by coercion - is there a way to tell it "yes this is what I want to do". Or should I just live with the warning?
Or should I be using a different function for this task?
?suppressWarnings
perhaps? – A5C1D2H2I1M1N2O1R2T1 Feb 20 '13 at 16:32suppressWarnings
seems perfect. – Korone Feb 20 '13 at 16:56read.table
accepts an argumentna.strings
? – Roland Feb 20 '13 at 17:03