Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何将案例分配到不规则的时间间隔?_R_Time Series_Zoo - Fatal编程技术网

R 如何将案例分配到不规则的时间间隔?

R 如何将案例分配到不规则的时间间隔?,r,time-series,zoo,R,Time Series,Zoo,我有以下数据帧 > head(elo) date elo 1 1921-12-18 1597 2 1922-05-14 1583 3 1922-05-28 1595 4 1922-09-03 1595 5 1922-10-01 1612 6 1923-06-03 1597 [...] > head(coaches) surname start stop Smith 1921-12-1

我有以下数据帧

> head(elo)
        date    elo
1 1921-12-18   1597
2 1922-05-14   1583
3 1922-05-28   1595
4 1922-09-03   1595
5 1922-10-01   1612
6 1923-06-03   1597
[...]
> head(coaches)
      surname       start        stop
        Smith  1921-12-18  1922-05-28
        White  1922-06-01  1923-06-28
        Black  1923-09-13  1928-01-01
输出应如下所示:

        date    elo  coach
1 1921-12-18   1597  Smith   
2 1922-05-14   1583  Smith  
3 1922-05-28   1595  Smith  
4 1922-09-03   1595  White  
5 1922-10-01   1612  White  
6 1923-06-03   1597  White      
[...]    
如何根据
start
stop
列将
coach$namel
分配给
elo
行?
coach
数据帧中的间隔不重叠。

lst=coach$start[x]&elo$date
lst <- lapply(1:nrow(coaches),function(x) 
             elo[which(elo$date >= coaches$start[x] & elo$date <= coaches$stop[x]),])
cbind(as.data.frame(do.call(rbind, lst)),
      coach = rep(coaches$surname, sapply(lst, function(x) nrow(x))))
        date  elo coach
1 1921-12-18 1597 Smith
2 1922-05-14 1583 Smith
3 1922-05-28 1595 Smith
4 1922-09-03 1595 White
5 1922-10-01 1612 White
6 1923-06-03 1597 White