I have a data frame as this, and want the output as shown desired at the end. Instead, I get the NA output in the middle. Is there any way to do what I want using dplyr?
x <- c(1234, 1234, 1234, 5678, 5678)
y <- c(95138, 30004, 90038, 01294, 15914)
z <- c('2014-01-20', '2014-10-30', '2015-04-12', '2010-2-28', '2015-01-01')
df <- data.frame(x, y, z)
df$z <- as.Date(df$z)
df %>% group_by(x) %>% summarise(y = y[max(z)])
What I get:
x y
1 1234 NA
2 5678 NA
Desired Output:
x y
1 1234 90038
2 5678 15914