aggregate 1-minute data into 5-minute average data

前端 未结 3 720
有刺的猬
有刺的猬 2020-12-01 05:35

My question here is to aggregate the data collected at every 1-minute into 5-minute average.

DeviceTime         Concentration
6/20/2013 11:13       
6/20/201         


        
3条回答
  •  庸人自扰
    2020-12-01 06:35

    I'd say the easiest and cleanest way to do this is using the lubridate and dplyr packages.

    library(lubridate)  # for working with dates
    library(dplyr)      # for manipulating data
    
    df$DeviceTime5min <- floor_date(df$DeviceTime, "5 mins")
    df_5min <- df %>% group_by(DeviceTime5min) %>% summarize(mean(Concentration))
    

    Only problem here is that it works just for values, that fit into an hour ... that is: 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60 min. But for these it works perfect :-)

提交回复
热议问题