I have data that looks like this:
data <- data.frame(unique_id = c(rep("A",6), rep("B",6)),
year = c(seq(2010,2015),seq(2010,2015)),
value = c(100,100,100,0,0,0,100,0,100,100,0,0))
I want this:
output <- data.frame(unique_id = c("A","B"),
year = c(2013,2014))
What's the most efficient way to do this? I think using dplyr along the lines of data %>% group_by(unique_id) %>% filter(value==0) %>% summarise(yr_closed = min(year))
would work, but this obviously doesn't return my desired output, and I don't know which functions to use to achieve this.
Thanks in advance!