I trying to use this function
chan <- function(x) {
for (i in x)
{assign(i,sample(1:10,2))}
out <- data.frame(sapply(x,get))
out
}
which x will be a list of string names, this function will assign 2 random numbers to each variable names and return it out as a data frame.
for example
x <- c("e","f")
When I use this function, it gives error
Error in FUN(..., ) : object ... not found
but if I don't use the function, just run the loop, it works. such as:
x <- c("e","f")
for (i in x)
{assign(i,sample(1:10,1))}
out <- data.frame(sapply(x,get))
I wonder what's wrong here.