-1

I have a data frame that looks like:

df <- data.frame(id=c(rep("no.234",20),rep("no.125",15)),y=rnorm(35))

I would like to use the bayes bootstrap on each id, iterate e.g., 1000 times, and put the result it in a list, using a loop or a pipe. The procedure for 1 id is:

require(bayesboot)
require(dplyr)
no.234 <- df %>% filter(id=="no.234")
bb <- bayesboot(no.234$y, R=1000)
rafa.pereira
  • 13,251
  • 6
  • 71
  • 109
  • Read about [apply family](https://www.datacamp.com/community/tutorials/r-tutorial-apply-family). – zx8754 Jun 15 '16 at 07:34

1 Answers1

0

Use sapply to cycle through all ids.

x <- sapply(levels(df$id), 
     FUN=function(x) bayesboot(df$y[df$id==x], statistic=mean, R=1000))

The result will be a list, where each element will contain the bootstrapped statistic for the given id.

nya
  • 2,138
  • 15
  • 29