[R] how to tell if as.numeric succeeds?

Steve Jaffe sjaffe at riskspan.com
Thu Jun 4 20:01:50 CEST 2009


Suppose I have a vector of strings. I'd like to convert this to a vector of
numbers if possible. How can I tell if it is possible? 

as.numeric() will issue a warning if it fails. Do I need to trap this
warning? If so, how?

In other words, my end goal is a function that takes a vector of strings and
returns either a numeric vector or the original vector. Assuming this
doesn't already exist, then to write it I'd need a function that returns
true if its input can be converted to numeric and false otherwise.

Any suggestions will be appreciated.
-- 
View this message in context: http://www.nabble.com/how-to-tell-if-as.numeric-succeeds--tp23874936p23874936.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list