我想创建一个数据框,其中包含一定时间范围内的值(max,min,mean,SD等)(date_inspection从date_begin到date_end的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)
dataset1:
id date_inspection value
123 2010/1/1 10.1
123 2010/1/2 9
123 2010/1/3 10.2
124 2010/1/1 20
124 2010/1/2 3.5
dataset2:
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
我想创建一个数据框,其中包含一定时间范围内的值(max,min,mean,SD等)(id为date_inspection,从date_begin到date_end),如下所示。
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
谢谢!