[R] symbolic iteration

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Jun 15 10:33:55 CEST 2004


I don't see why this needs to be iterative: the computations could be done
in parallel.  But via a for loop  you could use

for(i in 1:122) {
    nm <- paste("L", i, sep="")
    assign(nm, log(get(nm))
}

You would do better, I think, to have 122 similar data items in a list.

datalist <- lapply(1:122, function(x) get(paste("L", x, sep="")))

Then you could just do

logdatalist <- lapply(datalist, log)

and so on.

On Tue, 15 Jun 2004, Jin Shusong wrote:

>   I have 122 vectors named from L1 to L122.  Now I hope to
> take log to each of the series, say 
> L1 <- log(L1)
> ...
> L122<-log(L122)
> 
> Can anyone show me a iterative way to make the job simple.
> I mean the way something like
> for(i in 1:122){
>   ...
> }
> or other similar methods.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list