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

From: Mihai Bisca <mbisca_at_gmail.com>
Date: Sun, 13 May 2007 14:48:09 +0300

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,


R-help_at_stat.math.ethz.ch mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sun 13 May 2007 - 11:55:14 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 13 May 2007 - 13:31:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.