I'm trying to create a function, which creates n variables named automatically x1, x2, ..., xn. I have an approach, which works only through the console and not in a function (the runif creates an array of 1000 numbers between -1 and 1, which should be assigned to the variable):
for(i in 1:n) {
assign(sprintf("x%d",i),runif(1000,min=-1,max=1))
}
When I use it in a function, no variables are created in the environment...
I tried to make something like this:
for(i in 1:n) {
sprintf("x%d",i) <- runif(1000,min=-1,max=1))
}
But this returns the error "target of assignment expands to non-language object". Also tried to use as.name(), eval(), aso. But I didn't get the list of the variables x1 to xn in my environment through a function.
Could someone give me a hint? Thx a lot in advance!