r calculating rolling average with window based on value (not number of rows or date/time variable)

前端 未结 4 1171
小蘑菇
小蘑菇 2021-01-18 05:55

I\'m quite new to all the packages meant for calculating rolling averages in R and I hope you can show me in the right direction.

I have the following data as an exa

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-18 06:49

    You can try 'cut'. For example, if you want to divide ms such that you have 5 groups overall then you can do:

    df$ms_factor <- cut(df$ms, 5)
    
    df_new <- df %>% group_by(ms_factor) %>% summarise(mean = mean(correct)) 
    

提交回复
热议问题