【发布时间】:2021-04-09 21:07:00
【问题描述】:
我有一个索引列表,我想使用这些索引从数据框列表中提取观察结果。一个简化的例子如下:
#A list of indices used to extract observations based on the time column from the `dat` dataset
time.index <- list(c(1,2,3), c(4,5,6), c(2,3,4))
#A list of data frames in which observations will be extracted based on the time column
dat <- list(case1=data.frame(time=1:10, y=rnorm(10)), case2=data.frame(time=1:10, y=rnorm(10)), case3=data.frame(time=1:10, y=rnorm(10)))
#The expected result will be like this:
$case1
time y
1 1 -0.8954070
2 2 0.0270242
3 3 -0.4256890
$case2
time y
4 4 1.5789
5 5 -0.6692
6 6 -2.3306
$case3
time y
2 2 -0.7371
3 3 -0.3271
4 4 0.4128
有人知道如何实现吗?非常感谢!
【问题讨论】:
标签: r dataframe extract data-manipulation