Here's an example. I need to extract the minimum observation date in order to expand the table back to the commencement date. It was working, now it is not: producing an integer or a date near the origin 1970-01-10? I've tried converting to numeric and back, using as.Date() and changing the na function to na.omit and read lots of posts. I'm sure it's simple but it has defeated me.
library(tidyr)
library(lubridate)
tt <- tibble(month = factor(rep("Mar", 15)),
treatment = factor(rep(c("a", "b", "c"), each = 5)),
observation = c("", "", "", "05-04-2019", "",
"24-04-2019", "27-04-2019", "28-04-2019", "30-04-2019", "",
"05-05-2019", "09-05-2019", "12-05-2019", "20-05-2019", ""))
ts <- tt %>% mutate(observation = dmy(observation)) %>%
group_by(treatment) %>%
summarise(first = min(!is.na(observation)))
ts
# A tibble: 3 x 2
treatment first
* <fct> <int>
1 a 0
2 b 0
3 c 0