I know this is a duplicate Q but I can\'t seem to find the post again
Using the following data
df <- data.frame(A=c(1,1,2,2),B=c(NA,2,NA,4),C=c(3,
We can use fill to fill all the missing values. And then filter just one row for each group.
fill
library(dplyr) library(tidyr) df2 <- df %>% group_by(A) %>% fill(everything(), .direction = "down") %>% fill(everything(), .direction = "up") %>% slice(1)