I had previously asked this question on resampling and looping using dplyr function. The accepted solution was working just fine earlier, but not instead of giving 8000 values it's producing only one value of mean and variance. My R has also been throwing me error related to the 'stringi' package and it's being stubborn to recognize it even if it is installed. I wonder if the two are related? If it's not related, how can I obtain those 8000 values instead on 1 value for mean and variance?
The code I am currently running is:
library(dplyr)
fertilizer <- c("N","N","N","N","N","N","N","N","N","N","N","N","P","P","P","P","P","P","P","P","P","P","P","P","N","N","N","N","N","N","N","N","N","N","N","N","P","P","P","P","P","P","P","P","P","P","P","P")
crop <- c("alone","group","alone","group","alone","group","alone","group","alone","group","alone","group","alone","group","alone","group","alone","group","alone","group","alone","group","alone","group","alone","group","alone","group","alone","group","alone","group","alone","group","alone","group","alone","group","alone","group","alone","group","alone","group","alone","group","alone","group")
level <- c("low","low","high","high","low","low","high","high","low","low","high","high","low","low","high","high","low","low","high","high","low","low","high","high","low","low","high","high","low","low","high","high","low","low","high","high","low","low","high","high","low","low","high","high","low","low","high","low")
growth <- c(0,0,1,2,90,5,2,5,8,55,1,90,2,4,66,80,1,90,2,33,56,70,99,100,66,80,1,90,2,33,0,0,1,2,90,5,2,2,5,8,55,1,90,2,4,66,0,0)
dat <- data.frame(fertilizer, crop, level, growth)
dat %>%
group_by(fertilizer, crop, level) %>%
sample_n(3*1000, replace = T) %>%
mutate(sample_id = rep(1:1000, each = 3)) %>%
group_by(sample_id, add = TRUE) %>%
summarise(
mean = mean(growth, na.rm = T),
var = sd(growth)^2
) %>%
ungroup()