[R] convert a Character-string to a number

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Fri Sep 12 14:36:28 CEST 2003


"Michael Kirschbaum" <emkiba at gmx.de> writes:

> Hi Everyone.
> 
> I have a simple problem but don't know, how to get along.
> 
> how can I convert the vector
> 
> a<-c("0,01","1,00")
> in a vector 
> b<-c(0.01,1.00)
> 
> Thank you for suggestions

[Expect about 10 people to chime in...]

as.numeric(sub(",", ".", a))

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list