Basically the idea is for the values n=10,20,30,...100
to take the mean of 10,000 random samples, saving the 10,000 means for later usage.
In a language I'm more accustomed to, I would create a hashmap using each n
as a key, and a list of means as the value.
In javascript for example:
var mydata
var map = {}
for (int i = 10; i <= 100; i += 10 ) {
map[i] = [] // create list
for (int j = 0; j < 10000; j++) {
map[i][j] = mean(sample(mydata, i))
}
}
Now I attempted to do this in R (this is my first time using it), and I ended up with:
hashmap <- new.env()
sunspots <- read.table("sunspots.txt")
for (i in seq(10, 100, by=10)) {
hashmap[[i]] <- c()
for (j in 1:10000) {
hashmap[[i]][j] <- mean(sample(sunspots$x, i))
}
}
However this throws an error:
wrong args for environment subassignment
Even if it didn't throw this error, I'm not entirely sure if I'm approaching it the right way.
Could someone help me understand the proper way to go about this?