NAs introduced by coersion

Hi R studio community,

I want to stop the programming when "NAs introduced by coercion."

For example

character_vec<-c("2","c","0")
print(as.numeric(character_vec))

This returns
[1] 2 NA 0

and
Warning message: :NAs introduced by coercion

How can i return an error when this happens?

This should solve:

suppressWarnings(print(as.numeric(character_vec)))

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.