Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201977

R: Select earliest date after permanent change in status (not just earliest date conditional on status, but conditional on permanent change to status)

$
0
0

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!


Viewing all articles
Browse latest Browse all 201977

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>