Search code examples
rvariable-assignment

Mass variable declaration and assignment in R?


Apologies if this is a stupid question - but this my first attempt at using R, and i have ended up writting some code along the lines of:

some <- vector('list', length(files))
thing <- vector('list', length(files))
and <- vector('list', length(files))
another <- vector('list', length(files))
thing <- vector('list', length(files))

Is there a nicer (DRY) way to do this in R?

To rephrase, I want to assign the same value to multiple variables at once (as per @Sven Hohenstein's answer)


Solution

  • If you want to assign the same value to multiple variables at once, use this:

    some <- thing <- and <- another <- thing <- vector('list', length(files))