Skip to content
Prev 385368 / 398506 Next

filter() question

Hi Eberhard,
Here is one possibility using dplyr.

library(dplyr)
set.seed(3)

## set up some fake data
dtV <- as.Date("2020-08-01") + 0:4
x <- sample(dtV,20,repl=TRUE)
provider <- sample(LETTERS[1:3],20,repl=TRUE)
lDf <- data.frame(Provider=provider,CollectionDate=x,stringsAsFactors=FALSE)

## get min/max date for each provider
a <- lDf %>% dplyr::group_by( Provider ) %>%
  dplyr::mutate( minDt=min(CollectionDate), maxDt=max(CollectionDate)) %>%
  dplyr::summarize( u = min(minDt), v = max(maxDt) )

## get the common interval
c(max(a$u), min(a$v))

# [1] "2020-08-02" "2020-08-04"

HTH,
Eric
On Fri, Aug 21, 2020 at 12:34 PM Rasmus Liland <jral at posteo.no> wrote: