A data frame:
mydf <- data.frame(
date = seq(as.Date('2021-01-01'), as.Date('2021-01-20'), by = 'days'),
blah = rnorm(20, 0),
y = LETTERS[1:20]
)
I want to filter the date so that it goes all the way up to the maximum value of blah that's above 0.
Tried:
mydf %>% filter(date <= (. %>% filter(blah > 0) %>% pull(date) %>% max))
Which gave error:
Error: Problem with `filter()` input `..1`.
x comparison (4) is possible only for atomic and list types
ℹ Input `..1` is `date <= (. %>% filter(blah >= 0) %>% pull(date) %>% max)`.
How can I filter in this way?