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

Don MacQueen macq at llnl.gov
Wed Apr 23 18:11:05 CEST 2003


Oops.
Red face here.
-Don

At 5:42 PM +0200 4/23/03, Peter Dalgaard BSA wrote:
>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


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA



More information about the R-help mailing list