How to Check if a Date is Within a List of Intervals in R?












4















I have two data frames (tibbles) with 2 variables each:




  • df.POS: ID (ID variable); DATE (Date of positive lab test)

  • df.NEG: ID (ID variable); data (Date of negative lab tests (more than 1 test).


Please note that data is a list variable, created with the nest() function of the tidyr package.



library(tidyverse)
library(lubridate)

# negative tests
dates.neg <- ymd(c('2018-02-01', '2018-02-06', '2018-02-10',
'2018-02-21', '2018-04-05'))
df.NEG <- tibble(ID = paste0('ID_', rep(1, 5)),
DATE = dates.neg) %>%
group_by(ID) %>%
nest()
df.NEG

## # A tibble: 1 x 2
## ID data
## <chr> <list>
## 1 ID_1 <tibble [5 × 1]>


dates.pos <- ymd(c('2018-02-07', '2018-02-12', '2018-02-13',
'2018-02-20', '2018-02-21', '2018-03-18'))

df.POS <- tibble(ID = paste0('ID_', rep(1, 6)),
DATE = dates.pos)
df.POS

## # A tibble: 6 x 2
## ID DATE
## <chr> <date>
## 1 ID_1 2018-02-07
## 2 ID_1 2018-02-12
## 3 ID_1 2018-02-13
## 4 ID_1 2018-02-20
## 5 ID_1 2018-02-21
## 6 ID_1 2018-03-18


I would like to find out for which of the positive tests there was also a negative test up to 2 days after the positive test result. I've tried using the map2() function of the purrr package



df.TOTAL <- df.POS %>%
left_join(df.NEG, by = 'ID') %>%
mutate(TIME = interval(DATE, DATE + days(2)),
RESULT = map2(data, "DATE", TIME, ~ .x %within% .y))


Unfortunaltely, my code doesn't work. The RESULT variable should be logical and return TRUE in case of a negative test result up to 2 days after the positive test. Instead it is a list and returns NULL.



df.TOTAL

## # A tibble: 6 x 5
## ID DATE data TIME RESULT
## <chr> <date> <list> <S4: Interval> <list>
## 1 ID_1 2018-02-07 <tibble [5 × 1]> 2018-02-07 UTC--2018-02-09 UTC <NULL>
## 2 ID_1 2018-02-12 <tibble [5 × 1]> 2018-02-12 UTC--2018-02-14 UTC <NULL>
## 3 ID_1 2018-02-13 <tibble [5 × 1]> 2018-02-13 UTC--2018-02-15 UTC <NULL>
## 4 ID_1 2018-02-20 <tibble [5 × 1]> 2018-02-20 UTC--2018-02-22 UTC <NULL>
## 5 ID_1 2018-02-21 <tibble [5 × 1]> 2018-02-21 UTC--2018-02-23 UTC <NULL>
## 6 ID_1 2018-03-18 <tibble [5 × 1]> 2018-03-18 UTC--2018-03-20 UTC <NULL>


Can anyone help?



I would appreciate some help. Thanks very much in advance!










share|improve this question



























    4















    I have two data frames (tibbles) with 2 variables each:




    • df.POS: ID (ID variable); DATE (Date of positive lab test)

    • df.NEG: ID (ID variable); data (Date of negative lab tests (more than 1 test).


    Please note that data is a list variable, created with the nest() function of the tidyr package.



    library(tidyverse)
    library(lubridate)

    # negative tests
    dates.neg <- ymd(c('2018-02-01', '2018-02-06', '2018-02-10',
    '2018-02-21', '2018-04-05'))
    df.NEG <- tibble(ID = paste0('ID_', rep(1, 5)),
    DATE = dates.neg) %>%
    group_by(ID) %>%
    nest()
    df.NEG

    ## # A tibble: 1 x 2
    ## ID data
    ## <chr> <list>
    ## 1 ID_1 <tibble [5 × 1]>


    dates.pos <- ymd(c('2018-02-07', '2018-02-12', '2018-02-13',
    '2018-02-20', '2018-02-21', '2018-03-18'))

    df.POS <- tibble(ID = paste0('ID_', rep(1, 6)),
    DATE = dates.pos)
    df.POS

    ## # A tibble: 6 x 2
    ## ID DATE
    ## <chr> <date>
    ## 1 ID_1 2018-02-07
    ## 2 ID_1 2018-02-12
    ## 3 ID_1 2018-02-13
    ## 4 ID_1 2018-02-20
    ## 5 ID_1 2018-02-21
    ## 6 ID_1 2018-03-18


    I would like to find out for which of the positive tests there was also a negative test up to 2 days after the positive test result. I've tried using the map2() function of the purrr package



    df.TOTAL <- df.POS %>%
    left_join(df.NEG, by = 'ID') %>%
    mutate(TIME = interval(DATE, DATE + days(2)),
    RESULT = map2(data, "DATE", TIME, ~ .x %within% .y))


    Unfortunaltely, my code doesn't work. The RESULT variable should be logical and return TRUE in case of a negative test result up to 2 days after the positive test. Instead it is a list and returns NULL.



    df.TOTAL

    ## # A tibble: 6 x 5
    ## ID DATE data TIME RESULT
    ## <chr> <date> <list> <S4: Interval> <list>
    ## 1 ID_1 2018-02-07 <tibble [5 × 1]> 2018-02-07 UTC--2018-02-09 UTC <NULL>
    ## 2 ID_1 2018-02-12 <tibble [5 × 1]> 2018-02-12 UTC--2018-02-14 UTC <NULL>
    ## 3 ID_1 2018-02-13 <tibble [5 × 1]> 2018-02-13 UTC--2018-02-15 UTC <NULL>
    ## 4 ID_1 2018-02-20 <tibble [5 × 1]> 2018-02-20 UTC--2018-02-22 UTC <NULL>
    ## 5 ID_1 2018-02-21 <tibble [5 × 1]> 2018-02-21 UTC--2018-02-23 UTC <NULL>
    ## 6 ID_1 2018-03-18 <tibble [5 × 1]> 2018-03-18 UTC--2018-03-20 UTC <NULL>


    Can anyone help?



    I would appreciate some help. Thanks very much in advance!










    share|improve this question

























      4












      4








      4


      2






      I have two data frames (tibbles) with 2 variables each:




      • df.POS: ID (ID variable); DATE (Date of positive lab test)

      • df.NEG: ID (ID variable); data (Date of negative lab tests (more than 1 test).


      Please note that data is a list variable, created with the nest() function of the tidyr package.



      library(tidyverse)
      library(lubridate)

      # negative tests
      dates.neg <- ymd(c('2018-02-01', '2018-02-06', '2018-02-10',
      '2018-02-21', '2018-04-05'))
      df.NEG <- tibble(ID = paste0('ID_', rep(1, 5)),
      DATE = dates.neg) %>%
      group_by(ID) %>%
      nest()
      df.NEG

      ## # A tibble: 1 x 2
      ## ID data
      ## <chr> <list>
      ## 1 ID_1 <tibble [5 × 1]>


      dates.pos <- ymd(c('2018-02-07', '2018-02-12', '2018-02-13',
      '2018-02-20', '2018-02-21', '2018-03-18'))

      df.POS <- tibble(ID = paste0('ID_', rep(1, 6)),
      DATE = dates.pos)
      df.POS

      ## # A tibble: 6 x 2
      ## ID DATE
      ## <chr> <date>
      ## 1 ID_1 2018-02-07
      ## 2 ID_1 2018-02-12
      ## 3 ID_1 2018-02-13
      ## 4 ID_1 2018-02-20
      ## 5 ID_1 2018-02-21
      ## 6 ID_1 2018-03-18


      I would like to find out for which of the positive tests there was also a negative test up to 2 days after the positive test result. I've tried using the map2() function of the purrr package



      df.TOTAL <- df.POS %>%
      left_join(df.NEG, by = 'ID') %>%
      mutate(TIME = interval(DATE, DATE + days(2)),
      RESULT = map2(data, "DATE", TIME, ~ .x %within% .y))


      Unfortunaltely, my code doesn't work. The RESULT variable should be logical and return TRUE in case of a negative test result up to 2 days after the positive test. Instead it is a list and returns NULL.



      df.TOTAL

      ## # A tibble: 6 x 5
      ## ID DATE data TIME RESULT
      ## <chr> <date> <list> <S4: Interval> <list>
      ## 1 ID_1 2018-02-07 <tibble [5 × 1]> 2018-02-07 UTC--2018-02-09 UTC <NULL>
      ## 2 ID_1 2018-02-12 <tibble [5 × 1]> 2018-02-12 UTC--2018-02-14 UTC <NULL>
      ## 3 ID_1 2018-02-13 <tibble [5 × 1]> 2018-02-13 UTC--2018-02-15 UTC <NULL>
      ## 4 ID_1 2018-02-20 <tibble [5 × 1]> 2018-02-20 UTC--2018-02-22 UTC <NULL>
      ## 5 ID_1 2018-02-21 <tibble [5 × 1]> 2018-02-21 UTC--2018-02-23 UTC <NULL>
      ## 6 ID_1 2018-03-18 <tibble [5 × 1]> 2018-03-18 UTC--2018-03-20 UTC <NULL>


      Can anyone help?



      I would appreciate some help. Thanks very much in advance!










      share|improve this question














      I have two data frames (tibbles) with 2 variables each:




      • df.POS: ID (ID variable); DATE (Date of positive lab test)

      • df.NEG: ID (ID variable); data (Date of negative lab tests (more than 1 test).


      Please note that data is a list variable, created with the nest() function of the tidyr package.



      library(tidyverse)
      library(lubridate)

      # negative tests
      dates.neg <- ymd(c('2018-02-01', '2018-02-06', '2018-02-10',
      '2018-02-21', '2018-04-05'))
      df.NEG <- tibble(ID = paste0('ID_', rep(1, 5)),
      DATE = dates.neg) %>%
      group_by(ID) %>%
      nest()
      df.NEG

      ## # A tibble: 1 x 2
      ## ID data
      ## <chr> <list>
      ## 1 ID_1 <tibble [5 × 1]>


      dates.pos <- ymd(c('2018-02-07', '2018-02-12', '2018-02-13',
      '2018-02-20', '2018-02-21', '2018-03-18'))

      df.POS <- tibble(ID = paste0('ID_', rep(1, 6)),
      DATE = dates.pos)
      df.POS

      ## # A tibble: 6 x 2
      ## ID DATE
      ## <chr> <date>
      ## 1 ID_1 2018-02-07
      ## 2 ID_1 2018-02-12
      ## 3 ID_1 2018-02-13
      ## 4 ID_1 2018-02-20
      ## 5 ID_1 2018-02-21
      ## 6 ID_1 2018-03-18


      I would like to find out for which of the positive tests there was also a negative test up to 2 days after the positive test result. I've tried using the map2() function of the purrr package



      df.TOTAL <- df.POS %>%
      left_join(df.NEG, by = 'ID') %>%
      mutate(TIME = interval(DATE, DATE + days(2)),
      RESULT = map2(data, "DATE", TIME, ~ .x %within% .y))


      Unfortunaltely, my code doesn't work. The RESULT variable should be logical and return TRUE in case of a negative test result up to 2 days after the positive test. Instead it is a list and returns NULL.



      df.TOTAL

      ## # A tibble: 6 x 5
      ## ID DATE data TIME RESULT
      ## <chr> <date> <list> <S4: Interval> <list>
      ## 1 ID_1 2018-02-07 <tibble [5 × 1]> 2018-02-07 UTC--2018-02-09 UTC <NULL>
      ## 2 ID_1 2018-02-12 <tibble [5 × 1]> 2018-02-12 UTC--2018-02-14 UTC <NULL>
      ## 3 ID_1 2018-02-13 <tibble [5 × 1]> 2018-02-13 UTC--2018-02-15 UTC <NULL>
      ## 4 ID_1 2018-02-20 <tibble [5 × 1]> 2018-02-20 UTC--2018-02-22 UTC <NULL>
      ## 5 ID_1 2018-02-21 <tibble [5 × 1]> 2018-02-21 UTC--2018-02-23 UTC <NULL>
      ## 6 ID_1 2018-03-18 <tibble [5 × 1]> 2018-03-18 UTC--2018-03-20 UTC <NULL>


      Can anyone help?



      I would appreciate some help. Thanks very much in advance!







      r list date tidyr purrr






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 24 '18 at 17:18









      Norbert KöhlerNorbert Köhler

      405




      405
























          1 Answer
          1






          active

          oldest

          votes


















          3














          First, note that you can test whether any element from a vector of "negative" dates falls within the "positive" interval like so:



          any(dates.neg %within% interval(dates.pos[1], dates.pos[1] + days(2)))
          # [1] FALSE


          This suggests the following approach using map2 -- or more usefully, map2_lgl:



          df.TOTAL <- df.POS %>%
          left_join(df.NEG, by = 'ID') %>%
          mutate(TIME = interval(DATE, DATE + days(2)),
          RESULT = map2_lgl(data, TIME, ~any(.x$DATE %within% .y)))
          # # A tibble: 6 x 5
          # ID DATE data TIME RESULT
          # <chr> <date> <list> <S4: Interval> <lgl>
          # 1 ID_1 2018-02-07 <tibble [5 x 1]> 2018-02-07 UTC--2018-02-09 UTC FALSE
          # 2 ID_1 2018-02-12 <tibble [5 x 1]> 2018-02-12 UTC--2018-02-14 UTC FALSE
          # 3 ID_1 2018-02-13 <tibble [5 x 1]> 2018-02-13 UTC--2018-02-15 UTC FALSE
          # 4 ID_1 2018-02-20 <tibble [5 x 1]> 2018-02-20 UTC--2018-02-22 UTC TRUE
          # 5 ID_1 2018-02-21 <tibble [5 x 1]> 2018-02-21 UTC--2018-02-23 UTC TRUE
          # 6 ID_1 2018-03-18 <tibble [5 x 1]> 2018-03-18 UTC--2018-03-20 UTC FALSE


          Thanks to @ubutun for improving the answer.






          share|improve this answer


























          • Wouldn't be map2_lgl(data, TIME, ~ any(.x$DATE %within% y)) more self-explanatory? Anyway - great answer, thank you for the valuable information.

            – utubun
            Nov 24 '18 at 19:32













          • @utubun: Ah, that's right -- way more straightforward. I'll edit to reflect your suggestion.

            – Weihuang Wong
            Nov 24 '18 at 19:37











          • Thanks a lot. That's great! :-)

            – Norbert Köhler
            Nov 24 '18 at 19:54











          • @NorbertKöhler: Welcome to SO, and happy to help. If this answer resolved your question, please mark it as accepted.

            – Weihuang Wong
            Nov 24 '18 at 20:02











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460597%2fhow-to-check-if-a-date-is-within-a-list-of-intervals-in-r%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          First, note that you can test whether any element from a vector of "negative" dates falls within the "positive" interval like so:



          any(dates.neg %within% interval(dates.pos[1], dates.pos[1] + days(2)))
          # [1] FALSE


          This suggests the following approach using map2 -- or more usefully, map2_lgl:



          df.TOTAL <- df.POS %>%
          left_join(df.NEG, by = 'ID') %>%
          mutate(TIME = interval(DATE, DATE + days(2)),
          RESULT = map2_lgl(data, TIME, ~any(.x$DATE %within% .y)))
          # # A tibble: 6 x 5
          # ID DATE data TIME RESULT
          # <chr> <date> <list> <S4: Interval> <lgl>
          # 1 ID_1 2018-02-07 <tibble [5 x 1]> 2018-02-07 UTC--2018-02-09 UTC FALSE
          # 2 ID_1 2018-02-12 <tibble [5 x 1]> 2018-02-12 UTC--2018-02-14 UTC FALSE
          # 3 ID_1 2018-02-13 <tibble [5 x 1]> 2018-02-13 UTC--2018-02-15 UTC FALSE
          # 4 ID_1 2018-02-20 <tibble [5 x 1]> 2018-02-20 UTC--2018-02-22 UTC TRUE
          # 5 ID_1 2018-02-21 <tibble [5 x 1]> 2018-02-21 UTC--2018-02-23 UTC TRUE
          # 6 ID_1 2018-03-18 <tibble [5 x 1]> 2018-03-18 UTC--2018-03-20 UTC FALSE


          Thanks to @ubutun for improving the answer.






          share|improve this answer


























          • Wouldn't be map2_lgl(data, TIME, ~ any(.x$DATE %within% y)) more self-explanatory? Anyway - great answer, thank you for the valuable information.

            – utubun
            Nov 24 '18 at 19:32













          • @utubun: Ah, that's right -- way more straightforward. I'll edit to reflect your suggestion.

            – Weihuang Wong
            Nov 24 '18 at 19:37











          • Thanks a lot. That's great! :-)

            – Norbert Köhler
            Nov 24 '18 at 19:54











          • @NorbertKöhler: Welcome to SO, and happy to help. If this answer resolved your question, please mark it as accepted.

            – Weihuang Wong
            Nov 24 '18 at 20:02
















          3














          First, note that you can test whether any element from a vector of "negative" dates falls within the "positive" interval like so:



          any(dates.neg %within% interval(dates.pos[1], dates.pos[1] + days(2)))
          # [1] FALSE


          This suggests the following approach using map2 -- or more usefully, map2_lgl:



          df.TOTAL <- df.POS %>%
          left_join(df.NEG, by = 'ID') %>%
          mutate(TIME = interval(DATE, DATE + days(2)),
          RESULT = map2_lgl(data, TIME, ~any(.x$DATE %within% .y)))
          # # A tibble: 6 x 5
          # ID DATE data TIME RESULT
          # <chr> <date> <list> <S4: Interval> <lgl>
          # 1 ID_1 2018-02-07 <tibble [5 x 1]> 2018-02-07 UTC--2018-02-09 UTC FALSE
          # 2 ID_1 2018-02-12 <tibble [5 x 1]> 2018-02-12 UTC--2018-02-14 UTC FALSE
          # 3 ID_1 2018-02-13 <tibble [5 x 1]> 2018-02-13 UTC--2018-02-15 UTC FALSE
          # 4 ID_1 2018-02-20 <tibble [5 x 1]> 2018-02-20 UTC--2018-02-22 UTC TRUE
          # 5 ID_1 2018-02-21 <tibble [5 x 1]> 2018-02-21 UTC--2018-02-23 UTC TRUE
          # 6 ID_1 2018-03-18 <tibble [5 x 1]> 2018-03-18 UTC--2018-03-20 UTC FALSE


          Thanks to @ubutun for improving the answer.






          share|improve this answer


























          • Wouldn't be map2_lgl(data, TIME, ~ any(.x$DATE %within% y)) more self-explanatory? Anyway - great answer, thank you for the valuable information.

            – utubun
            Nov 24 '18 at 19:32













          • @utubun: Ah, that's right -- way more straightforward. I'll edit to reflect your suggestion.

            – Weihuang Wong
            Nov 24 '18 at 19:37











          • Thanks a lot. That's great! :-)

            – Norbert Köhler
            Nov 24 '18 at 19:54











          • @NorbertKöhler: Welcome to SO, and happy to help. If this answer resolved your question, please mark it as accepted.

            – Weihuang Wong
            Nov 24 '18 at 20:02














          3












          3








          3







          First, note that you can test whether any element from a vector of "negative" dates falls within the "positive" interval like so:



          any(dates.neg %within% interval(dates.pos[1], dates.pos[1] + days(2)))
          # [1] FALSE


          This suggests the following approach using map2 -- or more usefully, map2_lgl:



          df.TOTAL <- df.POS %>%
          left_join(df.NEG, by = 'ID') %>%
          mutate(TIME = interval(DATE, DATE + days(2)),
          RESULT = map2_lgl(data, TIME, ~any(.x$DATE %within% .y)))
          # # A tibble: 6 x 5
          # ID DATE data TIME RESULT
          # <chr> <date> <list> <S4: Interval> <lgl>
          # 1 ID_1 2018-02-07 <tibble [5 x 1]> 2018-02-07 UTC--2018-02-09 UTC FALSE
          # 2 ID_1 2018-02-12 <tibble [5 x 1]> 2018-02-12 UTC--2018-02-14 UTC FALSE
          # 3 ID_1 2018-02-13 <tibble [5 x 1]> 2018-02-13 UTC--2018-02-15 UTC FALSE
          # 4 ID_1 2018-02-20 <tibble [5 x 1]> 2018-02-20 UTC--2018-02-22 UTC TRUE
          # 5 ID_1 2018-02-21 <tibble [5 x 1]> 2018-02-21 UTC--2018-02-23 UTC TRUE
          # 6 ID_1 2018-03-18 <tibble [5 x 1]> 2018-03-18 UTC--2018-03-20 UTC FALSE


          Thanks to @ubutun for improving the answer.






          share|improve this answer















          First, note that you can test whether any element from a vector of "negative" dates falls within the "positive" interval like so:



          any(dates.neg %within% interval(dates.pos[1], dates.pos[1] + days(2)))
          # [1] FALSE


          This suggests the following approach using map2 -- or more usefully, map2_lgl:



          df.TOTAL <- df.POS %>%
          left_join(df.NEG, by = 'ID') %>%
          mutate(TIME = interval(DATE, DATE + days(2)),
          RESULT = map2_lgl(data, TIME, ~any(.x$DATE %within% .y)))
          # # A tibble: 6 x 5
          # ID DATE data TIME RESULT
          # <chr> <date> <list> <S4: Interval> <lgl>
          # 1 ID_1 2018-02-07 <tibble [5 x 1]> 2018-02-07 UTC--2018-02-09 UTC FALSE
          # 2 ID_1 2018-02-12 <tibble [5 x 1]> 2018-02-12 UTC--2018-02-14 UTC FALSE
          # 3 ID_1 2018-02-13 <tibble [5 x 1]> 2018-02-13 UTC--2018-02-15 UTC FALSE
          # 4 ID_1 2018-02-20 <tibble [5 x 1]> 2018-02-20 UTC--2018-02-22 UTC TRUE
          # 5 ID_1 2018-02-21 <tibble [5 x 1]> 2018-02-21 UTC--2018-02-23 UTC TRUE
          # 6 ID_1 2018-03-18 <tibble [5 x 1]> 2018-03-18 UTC--2018-03-20 UTC FALSE


          Thanks to @ubutun for improving the answer.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 24 '18 at 19:39

























          answered Nov 24 '18 at 19:15









          Weihuang WongWeihuang Wong

          9,7101835




          9,7101835













          • Wouldn't be map2_lgl(data, TIME, ~ any(.x$DATE %within% y)) more self-explanatory? Anyway - great answer, thank you for the valuable information.

            – utubun
            Nov 24 '18 at 19:32













          • @utubun: Ah, that's right -- way more straightforward. I'll edit to reflect your suggestion.

            – Weihuang Wong
            Nov 24 '18 at 19:37











          • Thanks a lot. That's great! :-)

            – Norbert Köhler
            Nov 24 '18 at 19:54











          • @NorbertKöhler: Welcome to SO, and happy to help. If this answer resolved your question, please mark it as accepted.

            – Weihuang Wong
            Nov 24 '18 at 20:02



















          • Wouldn't be map2_lgl(data, TIME, ~ any(.x$DATE %within% y)) more self-explanatory? Anyway - great answer, thank you for the valuable information.

            – utubun
            Nov 24 '18 at 19:32













          • @utubun: Ah, that's right -- way more straightforward. I'll edit to reflect your suggestion.

            – Weihuang Wong
            Nov 24 '18 at 19:37











          • Thanks a lot. That's great! :-)

            – Norbert Köhler
            Nov 24 '18 at 19:54











          • @NorbertKöhler: Welcome to SO, and happy to help. If this answer resolved your question, please mark it as accepted.

            – Weihuang Wong
            Nov 24 '18 at 20:02

















          Wouldn't be map2_lgl(data, TIME, ~ any(.x$DATE %within% y)) more self-explanatory? Anyway - great answer, thank you for the valuable information.

          – utubun
          Nov 24 '18 at 19:32







          Wouldn't be map2_lgl(data, TIME, ~ any(.x$DATE %within% y)) more self-explanatory? Anyway - great answer, thank you for the valuable information.

          – utubun
          Nov 24 '18 at 19:32















          @utubun: Ah, that's right -- way more straightforward. I'll edit to reflect your suggestion.

          – Weihuang Wong
          Nov 24 '18 at 19:37





          @utubun: Ah, that's right -- way more straightforward. I'll edit to reflect your suggestion.

          – Weihuang Wong
          Nov 24 '18 at 19:37













          Thanks a lot. That's great! :-)

          – Norbert Köhler
          Nov 24 '18 at 19:54





          Thanks a lot. That's great! :-)

          – Norbert Köhler
          Nov 24 '18 at 19:54













          @NorbertKöhler: Welcome to SO, and happy to help. If this answer resolved your question, please mark it as accepted.

          – Weihuang Wong
          Nov 24 '18 at 20:02





          @NorbertKöhler: Welcome to SO, and happy to help. If this answer resolved your question, please mark it as accepted.

          – Weihuang Wong
          Nov 24 '18 at 20:02




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460597%2fhow-to-check-if-a-date-is-within-a-list-of-intervals-in-r%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          To store a contact into the json file from server.js file using a class in NodeJS

          Redirect URL with Chrome Remote Debugging Android Devices

          Dieringhausen