[R] is.numeric

About this list Date view Thread view Subject view Author view Attachment view

From: Arne Henningsen (ahenningsen@email.uni-kiel.de)
Date: Thu 20 Feb 2003 - 20:58:46 EST


Message-id: <200302201058.46878.ahenningsen@email.uni-kiel.de>

Hi,
I have a vector, which contains both strings and numbers, e.g.

> foo <- c("str1",1234,"str2",0.9876)

I want to know if a distinct element of the vector is a string or a number and
took "is.numeric", but

> is.numeric(foo[2])
[1] FALSE

because R treats the numbers in a mixed vectors as strings:

> foo
[1] "str1" "1234" "str2" "0.9876"

As a workaround I use:

> !is.na(as.numeric(foo[2]))
[1] TRUE
> !is.na(as.numeric(foo[1]))
[1] FALSE
Warning message:
NAs introduced by coercion

This works, but I always get the spurious warning messages. Do you know a
better way or a way to suppress these warning messages?

Thanks,
Arne

-- 
Arne Henningsen
Department of Agricultural Economics
Christian-Albrechts-University Kiel
24098 Kiel, Germany
Tel: +49-431-880-4445
Fax: +49-431-880-1397 
ahenningsen@email.uni-kiel.de
http://www.uni-kiel.de/agrarpol/ahenningsen.html

______________________________________________ R-help@stat.math.ethz.ch mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Tue 01 Jul 2003 - 09:11:22 EST