【发布时间】:2022-01-24 03:26:39
【问题描述】:
我正在尝试根据不同个体所需的时间点列表来提取数据集的行。在 base R 中的实现方式是什么?
这是原始数据集:
data.frame(id=rep(1:3, each=3), time=1:3, y=c(1:9))
这是我想用来提取数据的每个 id 的时间点列表:
$`1` #this is id 1
[1] 1 2 #these are the time points I need for id 1
$`2`
[1] 1 3
$`3`
[1] 2 3
所以最终的数据是这样的:
id time y
1 1 1
1 2 2
2 1 4
2 3 6
3 2 8
3 3 9
【问题讨论】:
标签: r indexing data-manipulation data-cleaning