我有一个df:
ID | 年龄 | 测量 |
---|---|---|
1 | ||
1 | ||
1 | ||
2 | 0 | 10.0 |
2 | 0 | 11.5 |
2 | ||
2 | ||
3 | 0 | >td style="text align:central;">9.5|
3 | 1 | 20.00 |
4 | 0 | 10.5 |
4 | 0 | 11.0 |
4 | 1 | 23.5 |
4 | 2 | 26.5 |
4 | 3 | 27.5 |
library(tidyverse)
df %>%
group_by(ID, Age) %>%
slice_tail(n = 1) %>%
ungroup()
使用Dan的代码(谢谢!(:
df2<- RC_data %>%
filter(is.na(Age))
df<- df%>%
filter(!(is.na(Age))) %>%
group_by(ID, Age) %>%
slice_tail(n = 1) %>%
ungroup()
df<- full_join(df, df2)