[R] Looping through multiple datasets already in memory

Greg Snow Greg.Snow at imail.org
Fri Sep 9 23:31:27 CEST 2011

The best approach is to put all those datasets into a list, then you can loop through the elements of the list, or use lapply or sapply on the list.

If you insist on keeping them outside of a list, or need a loop to put them into the list, then look at the 'get' function.

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of MatAra
Sent: Friday, September 09, 2011 12:26 PM
To: r-help at r-project.org
Subject: [R] Looping through multiple datasets already in memory


I have the following loop:

for (i in (seq(along=Draw.1[,1]))) {print(i)} # from 1 - 5 (counter)
for (i in (seq(along=Draw.1[,1]))) {print(Draw[i,4])} # from the 1 - column
(passes parameter per column) 

Now: I have multiple Draws [Draw.1 - Draw.100] in memory with different
Question: How do I loop through  each Draw.[j]? OR in other way, how do I
pick up all the datasets from memory dynamically?

Something like: 
for (i in (seq(along=Draw.[J][,1]))) {print(Draw[i,4])}

paste() would not allow me to pick the [row,col] combination I need. It just
passes the list of all the elements.
paste(as.matrix(Draw), 1, sep=".")[10,5] DOES NOT WORK 

Thanks in advanced for the ideas!

An example of how the draw (control files) looks like:

      ID     Name                 Tab   Folder      L/S 
 [1,] "  38" "Stoxx50_24_08_11"   "38"  "Stoxx"     "-1"
 [2,] "  47" "Stoxx50_24_08_11"   "47"  "Stoxx"     " 1"
 [3,] " 153" "DAX_31_08_11"       "29"  "DAX"       " 1"
 [4,] " 256" "FT100_31_08_11"     "12"  "UK"        " 1"
 [5,] " 303" "FT100_31_08_11"     "59"  "UK"        " 1"

View this message in context: http://r.789695.n4.nabble.com/Looping-through-multiple-datasets-already-in-memory-tp3802453p3802453.html
Sent from the R help mailing list archive at Nabble.com.

R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list