0

Suppose I want to dynamically create data tables in a loop, for example:

for(i in 1:3){

  paste0('a',i)= data.table(x=1)


}

This returns an error. What is the syntax to do this properly?

wolfsatthedoor
  • 7,163
  • 18
  • 46
  • 90
  • Do you want to store these `data.table`s in a list? Try `n <- 3; setNames(replicate(n, data.table(x = 1), simplify = FALSE), nm = paste0("a", 1:n))` – markus Jan 09 '19 at 21:02
  • 3
    Well, the "correct" way is not to do this at all. Generally it's much better to work with variables in a list rather than creating a bunch of related variables with indexes embedded in their name. – MrFlick Jan 09 '19 at 21:06

0 Answers0