Calculating cumulative standard deviation by group using R

前端 未结 2 652
闹比i
闹比i 2021-01-14 12:29

I am pretty new to R and wanted to calculate the cumulative standard deviation by group in R. I have a data frame D which has an ID for visitor and the corresponding time on

2条回答
  •  抹茶落季
    2021-01-14 12:52

    You can do it with base functions:

    cumsd <- function(x) sapply(sapply(seq_along(x), head, x=x), sd)
    df1$cum_sd <- ave(df1$top, df1$ID, FUN=cumsd)
    

提交回复
热议问题