Lets say I have a list: x <- list(mtcars, iris, cars)
Now lets say I want to add another dataset to the list. Adding one to the end is easy. x[[4]]
You need to have a list
to add to the other list
s, so:
df <- data.frame(a=1:10)
c(list(df), x)
#List of 4
#...
You can use append
too, but you need to pass a list
again:
append(list(df),x)
# equivalent to:
append(x, list(df), after=0)
...which means you can specify exactly where you want df
added in the order of lists.
Yes, you use the append function. For example:
x <- list()
x <- append(x = x, c(mtcars, iris, cars))