I am working in R.
I have n
objects all named x
followed by a number j = 1,..., n
.
eg, for n = 5
:
x1, x2, x3, x4, x5
I want to be able to list them all together dynamically depending on the n
value:
list(x1,x2,x3,x4,x5)
In other words, I need to write a function that returns a list of those similarly-named objects automatically recognizing at what value of n
to stop.
I tried this:
l <- vector()
for (k in (1:n)){
if (k != n){
u <- paste0("x",k, ",")
} else {
u <- paste0("x",k)
}
l <- append(l,u)
}
But obviously returns a list of characters...
Does anyone have an idea of how to do that?
Many thanks for your help.