Re: [R] Sort a data frame

From: Kjetil Halvorsen <kjetil_at_acelerate.com>
Date: Wed 21 Jul 2004 - 05:07:57 EST

Gabor Grothendieck wrote:

>Gabor Grothendieck <ggrothendieck <at> myway.com> writes:
>
>
>
>>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.
>>
>>
Also:
library(Hmisc)
example(all.is.numeric)

Kjetil Halvorsen

>Sorry. The above has an error. It should be:
>
> # res is x converted to numeric or x without change if that fails
> res <- tryCatch(as.numeric(x), warning = function(warn)x)
>
>or
>
> # res is x converted to numeric or 0 if that fails
> res <- tryCatch(as.numeric(x), warning = function(warn)0)
>
>______________________________________________
>R-help@stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>
>
>



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jul 21 06:14:41 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:55:08 EST