[R] engineering notation format

Hans-Joerg Bibiko bibiko at eva.mpg.de
Fri Jul 7 11:27:07 CEST 2006


Hi,

try this:

formatEng <- function(x) {
   s<-as.numeric(strsplit(format(x, scientific=T),"e")[[1]])
   return(paste(s[1]*10^(s[2]%%3),as.integer(s[2]-(s[2]%%3)),sep="e"))
}

>>
>> Some examples:
>>
>> 1635 000 000      => 1.635E9
>>  163 500 000     => 163.5E6
>> 0.000 000 000 135 != 135E-9
>> 0.000 000 000 135 => 125E-12 ?


Hans

**********************************************************
Hans-Joerg Bibiko
Max Planck Institute for Evolutionary Anthropology
Department of Linguistics
Deutscher Platz 6     phone:   +49 (0) 341 3550 341
D-04103 Leipzig       fax:     +49 (0) 341 3550 333
Germany               e-mail:  bibiko at eva.mpg.de



More information about the R-help mailing list