[R] Check if a character vector can be coerced to numeric?
Jeff Newmiller
jdnewmil at dcn.davis.CA.us
Thu Mar 21 19:36:28 CET 2013
Using capital letters does not improve clarity... it just offends people.
Does read.table and friends not do this to your satisfaction already with as.is=TRUE? If not, shouldn't coercing it and checking for NA serve?
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
Jonathan Greenberg <jgrn at illinois.edu> wrote:
>Given an arbitrary set of character vectors:
>
>myvect1 <- c("abc","3","4")
>myvect2 <- c("2","3","4")
>
>I would like to develop a function that will convert any vectors that
>can
>be PROPERLY converted to a numeric (myvect2) into a numeric, but leaves
>character vectors which cannot be converted (myvect1) alone. Is there
>any
>simple way to do this (e.g. some function that tests if a vector is
>coercible to a numeric before doing so)?
>
>--j
More information about the R-help
mailing list