I would like to keep the first observation using the filter() function from dplyr. I mean, I would obtain many rows satisfying the same criterion from filtering but I only want to keep the first one, without further recurring to group() and distinct(). Is it possible?
I need to extract from a dataframe the first date stamp and the first date stamp where it appears "Bad".
problem = data.frame(
Status = c("Good", "Good", "Bad", "Bad", "Bad"),
Date_entry = c(as.Date("2000-01-01"), as.Date("2000-01-02"), as.Date("2000-01-03"), as.Date("2000-01-04"),as.Date("2000-01-05")),
Date_status = c(as.Date("1999-01-01"), as.Date("1999-01-01"), as.Date("1999-01-02"), as.Date("1999-01-02"), as.Date("1999-01-02")),
Value = c(150,20,14,96,04))
I can filter(Date == min(Date)) but then I don't know how to exactly filter out the first "Bad" outcome.
I tried filter(Date_entry== min(Date_entry) | (Date_status - Date_entry) == min(Date_status - Date_entry)) but still does not work
solution =
data.frame(Status = c("Good", "Bad"),
Date_entry = c(as.Date("2000-01-01"), as.Date("2000-01-02")),
Date_status = c(as.Date("1999-01-01"), as.Date("1999-01-02")),
Value = c(150,20))