这是一个可重现的测试数据集
mydata <- structure(list(subject = c(1, 1, 1, 2, 2, 2, 3, 3, 3), time = c(0, 1, 2, 0, 1, 2, 0, 1, 2), measure = c(10, 12, 8, 7, 0, 0, 5, 3, NA)), .Names = c("subject", "time", "measure"), row.names = 1:9, class = "data.frame")
mydata
subject time measure
1 0 10
1 1 12
1 2 8
2 0 7
2 1 0
2 2 0
3 0 5
3 1 3
3 2 NA
我想删除measure
NA 所在的所有行以及相同的所有相应行subject
。所以在上面的例子中,这将产生:
subject time measure
1 0 10
1 1 12
1 2 8
2 0 7
2 1 0
2 2 0
有没有一种简单的方法可以做到这一点而无需先重塑为宽格式?