[R] Using changing names in loop in R

Tuatara franziskabroell at gmail.com
Sat Nov 6 17:22:28 CET 2010


Hello everybody, 

I have usually solved this problem by repeating lines of codes instead of a
loop, but it's such a waste of time, I thought I should really learn how to
do it with loops:

What I want to do:

Say, I have several data files that differ only in a number, e.g. data
points (or vector, or matrix...) Data_1, Data_2, Data_3,... and I want to
manipulate them 

e.g. a simple sum of several data points

>data <- c(NA,n)
>for (i in 1:n){
>data[i] <- Data_i + Data_[i-1]
>                  } 

I know that the above code doesn't work, and I don't want to combine the
files into one vector to solve the problem etc. - I would just like to know
who make sure R recognizes the extension "_i". I have the same problem for
say, reading in datafiles that only differ by one digit in the extension,
and I want to (instead of repeating code) combine the process in a loop.

I hope I made myself clear to what my problem is.

Thanks for your help,

//F
-- 
View this message in context: http://r.789695.n4.nabble.com/Using-changing-names-in-loop-in-R-tp3030132p3030132.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list