[R] convert a Character-string to a number

Achim Zeileis zeileis at ci.tuwien.ac.at
Fri Sep 12 14:35:03 CEST 2003


On Friday 12 September 2003 14:29, Michael Kirschbaum wrote:

> 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)

You can use as.numeric(), but you need to change the decimal delimiter 
to ".", e.g.

R> as.numeric(gsub(",", ".", a))
[1] 0.01 1.00

hth,
Z

> Thank you for suggestions
>
> M.Kirschbaum
>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list