I am trying to run a simple bootstrap on the rows of a data frame in r. Here is what I have worked up so far, but I'm hitting a dead end.
x1 <- c(1:5)
x2 <- c(6:10)
y <- runif(5)
z <- as.data.frame(rbind(x1, x2, y))
trial <- 10
avg <- rep(0, trial)
for(i in 1:trial){
ind <- sample(ncol(z), size = ncol(z), replace = TRUE)
z.boot <- z[ind, ]
mean[i] <- mean(z.boot)
}
mean
Ideally, what I would like to do is to get a bootstrap weighted mean for the first and second rows with the weights in the third row but I can't even get my loop to work. There has to be a better way to do this. Any help is appreciated