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

Mihai Bisca
2007-05-13T11:48:09Z

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,

--
Mihai.