[R] Sort a data frame

Gabor Grothendieck ggrothendieck at myway.com
Tue Jul 20 15:21:00 CEST 2004


Liaw, Andy <andy_liaw <at> merck.com> writes:
> Does anyone know how to test whether a
> character can be coerced into numeric without generating a warning?

   res <- tryCatch(as.numeric(x), warning = function(x)x)

res is now numeric if x was successfully converted and is unchanged
if it was not.  You can test res using is.numeric and take
appropriate action or you can put the action into the body of the
warning function such as having it return 0.




More information about the R-help mailing list