【发布时间】:2020-11-05 01:29:22
【问题描述】:
我有一个数据集,其中包含多个个体在多个时间点的测量值。但是,对于某些人,我有一两个测量值,有些甚至四个(标准是 3)。查看示例数据:
从这个示例表中,我只需要 ID 1 和 2 的测量值,ID 3 有 3 个测量值,但时间点 2 测量了两次。 ID 4 和 5 缺少时间点。
有没有办法检查每个 ID 的测量是否完整?
我为此编写了一些代码:
get.completeTimepoints <- function(dataFrame){
unique.ids <- matrix(unique(dataFrame$id))
n.ids <- nrow(unique.ids)
for (i in 1:n.ids) {
temp.vector <- filter(dataFrame, id == unique.ids[i,]) #selects the id and all its measurements
validate.timepoints(temp.vector) #call validate function
}
}
我目前卡在如何检查是否存在所有三个时间点的测量值(请参阅下面的功能)。任何帮助将不胜感激
validate.timepoints <- function(dataFrame){
row.df <- nrow(dataFrame)
if(row.df ==3){
#check if all 3 timepoints are present in the dataframe
}
}
【问题讨论】:
-
请使用
dput或我们可以复制和使用的东西添加数据。图像没有帮助。还显示共享数据的预期输出。阅读how to ask a good question 和how to give a reproducible example。
标签: r