ns<-c(1,5,20,50,100,1000,10000)
Final<-rep(0,7)
second<-rep(0,10000)
for(i in length(ns)) {
second<-sample(1:1000,ns[i],replace=TRUE)
second[second==0]<-NA
Final[i]<- sd(second,na.rm=FALSE)
}
ns is the different sampling lengths I want to take. I created empty vectors Final and second to store values for my loop.
I was encountering issues where Final was returning mostly 0 values, so after thinking for a bit I decided to have all the zero values deleted from
second
every loop. But it hasn't helped, after running this code I get:
> Final
[1] 0.000 0.000 0.000 0.000 0.000 0.000 288.569
Now I'm stuck. Because when I read my code it seems very clear: Take a sample from 1:1000 of the number of units corresponding to the [i] of ns, given the ith loop. Then take the standard deviation of the nonzero values of the vector containing the sample and store it in another vector, Final.
Aucun commentaire:
Enregistrer un commentaire