[R] string to number conversion

Douglas Bates bates at stat.wisc.edu
Wed Jan 29 17:44:02 CET 2003


Serge Boiko <boiko at demogr.mpg.de> writes:

> Hi there;
> In order to convert sting to number I do:
> s <- "22"
> mode(s) <- "integer" # "double", etc. will do
> 
> Is that a "preferred" way?

Coersion functions are preferred.

> as.integer("22")
[1] 22
> as.numeric("22")
[1] 22

If you have the methods package attached you can use

> as("22", "numeric")
[1] 22




More information about the R-help mailing list