I'm using the boot() function from the boot package to bootstrap means from a population. The used function is:
boot_mean <- function(data, i){
ds_m <- data[i]
return(mean(ds_m))
}
Works like charm but now I want to adapt the boot_mean function so that I can get the samples which lead to the mean too. I tried:
library('boot')
boot_mean <- function(data, i){
ds_m <- data[i]
ds_m_mean <- mean(ds_m)
rlist <- list("means" = ds_m_mean, "data" = ds_m)
return(rlist)
}
dummy_data <- rnorm(500)
dummy_boot <- boot(dummy_data, boot_mean, R = 1000)
Which results in an error:
Error in t.star[r, ] <- res[[r]] : incorrect number of subscripts on matrix
What's wrong here? How can I get the corresponding dataset to the bootstrapped mean?