1

I want to create numerous data.frames so I wanted to automate it a bit.

## Some Loop   
i = i + 1
(paste('df',i,sep = '')) = data.frame(matrix(NA, nrow = 5, ncol = 1))
## Do some Task 

If I initialise i to 1, then for N passes through the loop I will create df1, df2 ... dfN.

But this doesn't work.

Do you have any ideas how I can fix my code/ a different approach I could look at?

Thanks,

Ben

Benjamin Busby
  • 45
  • 2
  • 10

1 Answers1

1

Try:

for(i in 1:10) {
  d = data.frame(matrix(NA, nrow = 5, ncol = 1))
  assign(paste("df", i, sep = ""), d)
}
timfaber
  • 2,060
  • 1
  • 15
  • 17