[R] Calculate daily means from 5-minute interval data

Rich Shepard r@hep@rd @end|ng |rom @pp|-eco@y@@com
Thu Sep 2 21:31:40 CEST 2021

On Thu, 2 Sep 2021, Andrew Simmons wrote:

> You could use 'split' to create a list of data frames, and then apply a
> function to each to get the means and sds.
> cols <- "cfs"  # add more as necessary
> S <- split(discharge[cols], format(discharge$sampdate, format = "%Y-%m"))
> means <- do.call("rbind", lapply(S, colMeans, na.rm = TRUE))
> sds   <- do.call("rbind", lapply(S, function(xx) sapply(xx, sd, na.rm =
> TRUE)))


Thank you for the valuable lesson. This is new to me and I know I'll have
use for it in the future, too.

Much appreciated!

Stay well,


More information about the R-help mailing list