R

Asked • 10/03/19

How to avoid warning when introducing NAs by coercion?

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?

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.