Dear all, 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. Many thanks. Jin
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
Dear Jin, you could try something like, L1 <- runif(10) L2 <- runif(20) L3 <- runif(30) L4 <- runif(40) res <- vector(mode="list", length=4) ss <- paste("log(L", 1:4, ")", sep="") for(i in 1:4) res[[i]] <- eval(parse(text=ss[i])) res I hope this helps. Best, Dimitris ---- Dimitris Rizopoulos Doctoral Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/396887 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Jin Shusong" <jinss at hkusua.hku.hk> To: "R Help" <r-help at stat.math.ethz.ch> Sent: Tuesday, June 15, 2004 10:06 AM Subject: [R] symbolic iteration> Dear all, > 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. > Many thanks. > > > Jin > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide!http://www.R-project.org/posting-guide.html