Here is my current code... can I make this a for loop?
#sample1, sample2, …, sample6 where samplei is sampling 10^(ith)
sample1 <- abs(rnorm(10)) #use abs because bellcurve is + and -
sample2 <- abs(rnorm(10^2))
sample3 <- abs(rnorm(10^3))
sample <- abs(rnorm(10^4))
sample5 <- abs(rnorm(10^5))
sample6 <- abs(rnorm(10^6))
If you also want to assign it to 6 different variables you will need to do:
n = 6
invisible(sapply(1:n, function(i) assign(x = paste("sample", i, sep = ""),
value = abs(rnorm(10^i)),
envir = .GlobalEnv)))
Or with a for loop:
for(i in 1:n)
{
assign(x = paste("sample", i, sep = ""), value = abs(rnorm(10^i)), envir = .GlobalEnv)
}
But it makes much more sense to store it as a list, like in:
samples = lapply(1:6, function(i) abs(rnorm(10^i)))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments