[R] How do I get 10^4 to become 10000?

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Wed Apr 23 17:42:31 CEST 2003


Don MacQueen <macq at llnl.gov> writes:

> How about this?
> 
> >  a <- c('10^4','1.2^3','2.3')
> 
> >  as.numeric(gsub('\\^','E',a))
> [1] 1.0e+05 1.2e+03 2.3e+00
> 
> This solution doesn't work for "10^(-5)" but does work for "10^-5".
> 

Didn't work too well for 1.2^3 by some standards... 

> a <- c('10^4','1.2^3','2.3')
> sapply(parse(text=a),eval)
[1] 10000.000     1.728     2.300

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907



More information about the R-help mailing list