0

I want to use a for loop to perform the same function on multiple similarly named data.frames. Is there a way to do this? This is my current attempt:

for(i in colnames(SellList)){
  as.data.frame([i].sub) <- [[paste("SaleAmount")]] <- SellList[1,i]
}

where the data.frames being pasted to are named A.sub, B.sub, etc. and the column names are A, B, etc.

Nick
  • 45
  • 4
  • what exactly should it do? Extract from SellList[1,i], paste it with SaleAmount and save in a data frame? Those arrows dont work do they? You can do something like this with 'magrittr' pipes %>% so SellList[1,i] %>% [[paste("SaleAmount"]] %>% as.data.frame([i].sub) And this surely will be doable with apply family of functions. Could you show the data and what it the result should look like? – Jan Sila Jul 11 '16 at 20:56
  • See [this post](http://stackoverflow.com/questions/17499013/how-do-i-make-a-list-of-data-frames) on putting data.frames into a list. Gregor's answer on how to work with such lists will be of particular interest. This is the preferred method in R. – lmo Jul 11 '16 at 23:00
  • I would be very surprised if there were an `as.data.frame.<-` function. The notion of using a dot as an accessor to a bracketed character value ( `[i].sub` ) appears totally alien to R syntax. I'm guessing you have dropped in from a different programming universe. You need to learn how to operate on a single data-object before you try to do it in a loop. – IRTFM Jul 11 '16 at 23:50

0 Answers0