[R] how to convert a string vector to a numeric vector

Mihai Bisca mbisca at gmail.com
Sun May 13 13:48:09 CEST 2007

Hello all,

I'm new to R and I cannot find a simple answer to a simple question.
If I have a character vector like v <- c('1/50,'1/2','1/8'...) how can
I convert it to a numeric vector like vn <- c(0.02,0.5,0.125...). I
tried as.numeric in various ways and failed miserably. Currently I use
a function like: for (e in v) { if (e=='1/50') vn<-c(vn,0.02) ...} but
that feels bad because it needs to be (humanly) modified everytime a
new fraction appears in v.

Thanks in advance,


More information about the R-help mailing list