Re: [R] Convert character string to number

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Sat, 21 Jun 2008 13:25:30 +0200

Kenn Konstabel wrote:
> another way to do it is using eval and parse:
>
> yyy<-numeric()
> for(i in 1:length(xxx)) yyy[i] <- eval(parse(text=xxx[i]))
>
> or ...
>
> unlist(lapply(as.list(xxx), function(x) eval(parse(text=x))))
>
>
or even

sapply(parse(text=xxx), eval)

(Beware that this can have unforeseen side effects depending on the content of xxx, though.)

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard_at_biostat.ku.dk)              FAX: (+45) 35327907

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 21 Jun 2008 - 11:35:02 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 Sat 21 Jun 2008 - 12:30:57 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.

list of date sections of archive