[R] logarithmic seq() ?

Oliver Bandel oliver at first.in-berlin.de
Tue Sep 22 01:10:01 CEST 2009


 <Ted.Harding <at> manchester.ac.uk> writes:

> 
> On 21-Sep-09 18:47:50, Oliver Bandel wrote:
> > Hello,
> > in scilab /Matlab there are functions that can create linear
> > sequences (like R's seq()) as well as logarithmic sequences.
> > 
> > 
> > Is there a logarithmic aequivalent of seq()?
> > Or maybe this would be an idea for newer R-releases,
> > maybe a type-option with "linear" and "logarithmic" as
> > parameters....?!
> > 
> > Ciao,
> >   Oliver
> 
> If you mean going from a to b by "logarithmically equal" steps,
> then you can quite readily implement it yourself. For example:
> 
> exp(log(10)*seq(log10(1),log10(100),by=0.25)
> [1]   1.000000   1.778279   3.162278   5.623413  10.000000
> [6]  17.782794  31.622777  56.234133 100.000000
[...]


OK, thanks for the hint.

I adapted your example...

...to create a function that offers what scilab's logspace()
offers:


> logspace <- function( d1, d2, n) exp(log(10)*seq(d1, d2, length.out=n))
> logspace( 1, 2, 10 )
 [1]  10.00000  12.91550  16.68101  21.54435  27.82559  35.93814  46.41589
 [8]  59.94843  77.42637 100.00000
> logspace( 1, 7.2, 10 )
 [1] 1.000000e+01 4.885274e+01 2.386590e+02 1.165914e+03 5.695811e+03
 [6] 2.782559e+04 1.359356e+05 6.640828e+05 3.244226e+06 1.584893e+07
> 


But maybe your example (with the logarithms of the arguments)
make even more sense... :-)


Ciao,
   Oliver




More information about the R-help mailing list