So I have my problem below and R code: (The nile data is one of R's included datasets)
seed random number generator Define an empty or 1000-element vector, "sample1," to write sample means to Write for-loop to drawn 1000 random samples, n = 25, and write mean of sample to prepared vector
data <- as.vector(Nile)
set.seed(123)
sample1 <- vector()
for(i in 1:1000){
r <- vector()
r[i] <- data[sample(1:100,size=25,replace=1)]
sample1[i] <- mean(r[i])
}
and I am getting a warning message in my output saying:
Warning in r[i] <- data[sample(1:100, size = 25, replace = 1)]: number of items to replace is not a multiple of replacement length
Could anyone help me out?
r[i] <- data[.....]
. You can get rid of the wholer
thing and compute mean on thedata[blah...]
– Gopalasample1 <- sapply(1:1000, function(i) { mean(data[sample(1:100, size=25, replace=TRUE)]) })
– ekstroem