R 需要一个函数来处理时间范围和id匹配

R 需要一个函数来处理时间范围和id匹配,r,R,我想制作一个数据帧,其中包含特定时间范围内的值(最大值、最小值、平均值、SD等)(检查日期从日期开始到日期结束的id值),如下所示 date_inspection <-c("2010-01-01 00:00:00","2010-01-02 00:00:00","2010-01-03 00:00:00","2010-01-01 00:00:00", "2010-01-02 00:00:00") date_inspection <-as.POSIXct(date_inspect

我想制作一个数据帧,其中包含特定时间范围内的值(最大值、最小值、平均值、SD等)(检查日期从日期开始到日期结束的id值),如下所示

date_inspection <-c("2010-01-01 00:00:00","2010-01-02 00:00:00","2010-01-03 00:00:00","2010-01-01 00:00:00",
     "2010-01-02 00:00:00")
date_inspection <-as.POSIXct(date_inspection)

date_begin <-c("2010-01-01 00:00:00","2015-01-01 00:00:00","2010-01-01 00:00:00","2016-03-03 00:00:00")
date_begin <-as.POSIXct(date_begin)

date_end <-c("2010-01-04 00:00:00","2015-02-01 00:00:00","2010-02-02 00:00:00","2016-03-05 00:00:00")
date_end <-as.POSIXct(date_end)

id1 <-c(123,123,123,124,124)

id2 <-c(123,123,124,124)
value <-c(10.1,9.0,10.2,20,3.5)
data_set1 <-cbind(id=id1,date_inspection,value)
data_set2 <-cbind(id=id2,date_begin,date_end)
id     date_begin         date_end          
123     2010/1/1          2010/1/4          
123     2015/1/1          2015/2/1          
124     2010/1/1          2010/2/2          
124     2016/3/3          2016/3/5          
数据集2:

id     date_begin         date_end          
123     2010/1/1          2010/1/4          
123     2015/1/1          2015/2/1          
124     2010/1/1          2010/2/2          
124     2016/3/3          2016/3/5          
我想制作一个数据帧,其中包含特定时间范围内的值(最大值、最小值、平均值、标准差等)(id“date\u inspection from date\u begin to date\u end”),如下所示

id     date_begin         date_end          
123     2010/1/1          2010/1/4          
123     2015/1/1          2015/2/1          
124     2010/1/1          2010/2/2          
124     2016/3/3          2016/3/5          
id     date_begin    date_end     max      min      mean      list  
123    2010/1/1      2010/1/4     10.2      9       9.8       (10.2,9,10.2)     
123    2015/1/1      2015/2/1     NA       NA       NA         NA   
124    2010/1/1      2010/2/2     20       3.5      11.8      (20,3.5)    
124    2016/3/3      2016/3/5     NA       NA       NA         NA   
谢谢大家!

id     date_begin         date_end          
123     2010/1/1          2010/1/4          
123     2015/1/1          2015/2/1          
124     2010/1/1          2010/2/2          
124     2016/3/3          2016/3/5