rollmean with dplyr and magrittr

后端 未结 2 1667
梦毁少年i
梦毁少年i 2020-12-09 04:59

Given the following data:

    set.seed(1)
    data <- data.frame(o=c(\'a\',\'a\',\'a\',\'a\',\'b\',\'b\',\'b\',\'b\',\'c\',\'c\',\'c\',\'c\'), t=c(1,2,3,4         


        
2条回答
  •  情话喂你
    2020-12-09 05:48

    A more flexible wrapper comes from the rowr package. This allows for windows of different size within your initial data.

    data %>% 
    group_by(o) %>% 
    mutate(MEANS = rollApply(u, fun=mean, window=3, align='right'))
    

提交回复
热议问题