Search code examples
rdatetidyversedata-wrangling

Find Overlap in Dates Between Multiple Date Columns in the Same DF


I have a df as below where each column (v1-v10) is a unique set of dates from 10 other data frames containing various data. I want to find the date range/ranges in which all columns (v1-v10) share. Ultimately I want to be returned columns v1-v10 with dates in which are shared across all 10 columns/data frames.

Data


data <- structure(list(v1 = structure(c(1658361600, 1658361600, 1658448000, 
1658448000, 1658448000, 1658448000, 1658534400, 1658534400, 1658534400, 
1658534400, 1658620800, 1658620800, 1658620800, 1658620800, 1658707200, 
1658707200, 1658707200, 1658707200, 1658793600, 1658793600, 1658793600, 
1658793600, 1658880000, 1658880000, 1658880000, 1658880000, 1658966400, 
1658966400, 1658966400, 1658966400, 1659052800, 1659052800, 1659052800, 
1659052800, 1659139200, 1659139200, 1659139200, 1659139200, 1659225600, 
1659225600, 1659225600, 1659225600, 1659312000, 1659312000, 1659312000, 
1659312000, 1659398400, 1659398400, 1659398400, 1659398400, 1659484800, 
1659484800, 1659484800, 1659484800, 1659571200, 1659571200, 1659571200, 
1659571200, 1659657600, 1659657600, 1659657600, 1659657600, 1659744000, 
1659744000, 1659744000, 1659744000, 1659830400, 1659830400, 1659830400, 
1659830400, 1659916800, 1659916800, 1659916800, 1659916800, 1660003200, 
1660003200, 1660003200, 1660003200, 1660089600, 1660089600, 1660089600, 
1660089600, 1660176000, 1660176000, 1660176000, 1660176000, 1660262400, 
1660262400, 1660262400, 1660262400, 1660348800, 1660348800, 1660348800, 
1660348800, 1660435200, 1660435200, 1660435200, 1660435200, 1660521600, 
1660521600), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
    v2 = structure(c(1665705600, 1665705600, 1665705600, 1665705600, 
    1665792000, 1665792000, 1665792000, 1665792000, 1665792000, 
    1665792000, 1665878400, 1665878400, 1665878400, 1665878400, 
    1665878400, 1665878400, 1665964800, 1665964800, 1665964800, 
    1665964800, 1665964800, 1665964800, 1666051200, 1666051200, 
    1666051200, 1666051200, 1666051200, 1666051200, 1666137600, 
    1666137600, 1666137600, 1666137600, 1666137600, 1666137600, 
    1666224000, 1666224000, 1666224000, 1666224000, 1666224000, 
    1666224000, 1666310400, 1666310400, 1666310400, 1666310400, 
    1666310400, 1666310400, 1666396800, 1666396800, 1666396800, 
    1666396800, 1666396800, 1666396800, 1666483200, 1666483200, 
    1666483200, 1666483200, 1666483200, 1666483200, 1666569600, 
    1666569600, 1666569600, 1666569600, 1666569600, 1666569600, 
    1666656000, 1666656000, 1666656000, 1666656000, 1666656000, 
    1666656000, 1666742400, 1666742400, 1666742400, 1666742400, 
    1666742400, 1666742400, 1666828800, 1666828800, 1666828800, 
    1666828800, 1666828800, 1666828800, 1666915200, 1666915200, 
    1666915200, 1666915200, 1666915200, 1666915200, 1667001600, 
    1667001600, 1667001600, 1667001600, 1667001600, 1667001600, 
    1667088000, 1667088000, 1667088000, 1667088000, 1667088000, 
    1667088000), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
    v3 = structure(c(1658534400, 1658534400, 1658534400, 1658620800, 
    1658620800, 1658620800, 1658620800, 1658620800, 1658620800, 
    1658707200, 1658707200, 1658707200, 1658707200, 1658707200, 
    1658707200, 1658793600, 1658793600, 1658793600, 1658793600, 
    1658793600, 1658793600, 1658880000, 1658880000, 1658880000, 
    1658880000, 1658880000, 1658880000, 1658966400, 1658966400, 
    1658966400, 1658966400, 1658966400, 1658966400, 1659052800, 
    1659052800, 1659052800, 1659052800, 1659052800, 1659052800, 
    1659139200, 1659139200, 1659139200, 1659139200, 1659139200, 
    1659139200, 1659225600, 1659225600, 1659225600, 1659225600, 
    1659225600, 1659225600, 1659312000, 1659312000, 1659312000, 
    1659312000, 1659312000, 1659312000, 1659398400, 1659398400, 
    1659398400, 1659398400, 1659398400, 1659398400, 1659484800, 
    1659484800, 1659484800, 1659484800, 1659484800, 1659484800, 
    1659571200, 1659571200, 1659571200, 1659571200, 1659571200, 
    1659571200, 1659657600, 1659657600, 1659657600, 1659657600, 
    1659657600, 1659657600, 1659744000, 1659744000, 1659744000, 
    1659744000, 1659744000, 1659744000, 1659830400, 1659830400, 
    1659830400, 1659830400, 1659830400, 1659830400, 1659916800, 
    1659916800, 1659916800, 1659916800, 1659916800, 1659916800, 
    1660003200), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
    v4 = structure(c(1658534400, 1658534400, 1658620800, 1658620800, 
    1658620800, 1658620800, 1658707200, 1658707200, 1658707200, 
    1658707200, 1658793600, 1658793600, 1658793600, 1658793600, 
    1658880000, 1658880000, 1658880000, 1658880000, 1658966400, 
    1658966400, 1658966400, 1658966400, 1659052800, 1659052800, 
    1659052800, 1659052800, 1659139200, 1659139200, 1659139200, 
    1659139200, 1659225600, 1659225600, 1659225600, 1659225600, 
    1659312000, 1659312000, 1659312000, 1659312000, 1659398400, 
    1659398400, 1659398400, 1659398400, 1659484800, 1659484800, 
    1659484800, 1659484800, 1659571200, 1659571200, 1659571200, 
    1659571200, 1659657600, 1659657600, 1659657600, 1659657600, 
    1659744000, 1659744000, 1659744000, 1659744000, 1659830400, 
    1659830400, 1659830400, 1659830400, 1659916800, 1659916800, 
    1659916800, 1659916800, 1660003200, 1660003200, 1660003200, 
    1660003200, 1660089600, 1660089600, 1660089600, 1660089600, 
    1660176000, 1660176000, 1660176000, 1660176000, 1660262400, 
    1660262400, 1660262400, 1660262400, 1660348800, 1660348800, 
    1660348800, 1660348800, 1660435200, 1660435200, 1660435200, 
    1660435200, 1660521600, 1660521600, 1660521600, 1660521600, 
    1660608000, 1660608000, 1660608000, 1660608000, 1660694400, 
    1660694400), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
    v5 = structure(c(1658966400, 1658966400, 1659052800, 1659052800, 
    1659052800, 1659052800, 1659139200, 1659139200, 1659139200, 
    1659139200, 1659225600, 1659225600, 1659225600, 1659225600, 
    1659312000, 1659312000, 1659312000, 1659312000, 1659398400, 
    1659398400, 1659398400, 1659398400, 1659484800, 1659484800, 
    1659484800, 1659484800, 1659571200, 1659571200, 1659571200, 
    1659571200, 1659657600, 1659657600, 1659657600, 1659657600, 
    1659744000, 1659744000, 1659744000, 1659744000, 1659830400, 
    1659830400, 1659830400, 1659830400, 1659916800, 1659916800, 
    1659916800, 1659916800, 1660003200, 1660003200, 1660003200, 
    1660003200, 1660089600, 1660089600, 1660089600, 1660089600, 
    1660176000, 1660176000, 1660176000, 1660176000, 1660262400, 
    1660262400, 1660262400, 1660262400, 1660348800, 1660348800, 
    1660348800, 1660348800, 1660435200, 1660435200, 1660435200, 
    1660435200, 1660521600, 1660521600, 1660521600, 1660521600, 
    1660608000, 1660608000, 1660608000, 1660608000, 1660694400, 
    1660694400, 1660694400, 1660694400, 1660780800, 1660780800, 
    1660780800, 1660780800, 1660867200, 1660867200, 1660867200, 
    1660867200, 1660953600, 1660953600, 1660953600, 1660953600, 
    1661040000, 1661040000, 1661040000, 1661040000, 1661126400, 
    1661126400), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
    v6 = structure(c(1659052800, 1659139200, 1659139200, 1659139200, 
    1659139200, 1659225600, 1659225600, 1659225600, 1659225600, 
    1659312000, 1659312000, 1659312000, 1659312000, 1659398400, 
    1659398400, 1659398400, 1659398400, 1659484800, 1659484800, 
    1659484800, 1659484800, 1659571200, 1659571200, 1659571200, 
    1659571200, 1659657600, 1659657600, 1659657600, 1659657600, 
    1659744000, 1659744000, 1659744000, 1659744000, 1659830400, 
    1659830400, 1659830400, 1659830400, 1659916800, 1659916800, 
    1659916800, 1659916800, 1660003200, 1660003200, 1660003200, 
    1660003200, 1660089600, 1660089600, 1660089600, 1660089600, 
    1660176000, 1660176000, 1660176000, 1660176000, 1660262400, 
    1660262400, 1660262400, 1660262400, 1660348800, 1660348800, 
    1660348800, 1660348800, 1660435200, 1660435200, 1660435200, 
    1660435200, 1660521600, 1660521600, 1660521600, 1660521600, 
    1660608000, 1660608000, 1660608000, 1660608000, 1660694400, 
    1660694400, 1660694400, 1660694400, 1660780800, 1660780800, 
    1660780800, 1660780800, 1660867200, 1660867200, 1660867200, 
    1660867200, 1660953600, 1660953600, 1660953600, 1660953600, 
    1661040000, 1661040000, 1661040000, 1661040000, 1661126400, 
    1661126400, 1661126400, 1661126400, 1661212800, 1661212800, 
    1661212800), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
    v7 = structure(c(1658707200, 1658793600, 1658793600, 1658793600, 
    1658793600, 1658880000, 1658880000, 1658880000, 1658880000, 
    1658966400, 1658966400, 1658966400, 1658966400, 1659052800, 
    1659052800, 1659052800, 1659052800, 1659139200, 1659139200, 
    1659139200, 1659139200, 1659225600, 1659225600, 1659225600, 
    1659225600, 1659312000, 1659312000, 1659312000, 1659312000, 
    1659398400, 1659398400, 1659398400, 1659398400, 1659484800, 
    1659484800, 1659484800, 1659484800, 1659571200, 1659571200, 
    1659571200, 1659571200, 1659657600, 1659657600, 1659657600, 
    1659657600, 1659744000, 1659744000, 1659744000, 1659744000, 
    1659830400, 1659830400, 1659830400, 1659830400, 1659916800, 
    1659916800, 1659916800, 1659916800, 1660003200, 1660003200, 
    1660003200, 1660003200, 1660089600, 1660089600, 1660089600, 
    1660089600, 1660176000, 1660176000, 1660176000, 1660176000, 
    1660262400, 1660262400, 1660262400, 1660262400, 1660348800, 
    1660348800, 1660348800, 1660348800, 1660435200, 1660435200, 
    1660435200, 1660435200, 1660521600, 1660521600, 1660521600, 
    1660521600, 1660608000, 1660608000, 1660608000, 1660608000, 
    1660694400, 1660694400, 1660694400, 1660694400, 1660780800, 
    1660780800, 1660780800, 1660780800, 1660867200, 1660867200, 
    1660867200), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
    v8 = structure(c(1658707200, 1658793600, 1658793600, 1658793600, 
    1658793600, 1658880000, 1658880000, 1658880000, 1658880000, 
    1658966400, 1658966400, 1658966400, 1658966400, 1659052800, 
    1659052800, 1659052800, 1659052800, 1659139200, 1659139200, 
    1659139200, 1659139200, 1659225600, 1659225600, 1659225600, 
    1659225600, 1659312000, 1659312000, 1659312000, 1659312000, 
    1659398400, 1659398400, 1659398400, 1659398400, 1659484800, 
    1659484800, 1659484800, 1659484800, 1659571200, 1659571200, 
    1659571200, 1659571200, 1659657600, 1659657600, 1659657600, 
    1659657600, 1659744000, 1659744000, 1659744000, 1659744000, 
    1659830400, 1659830400, 1659830400, 1659830400, 1659916800, 
    1659916800, 1659916800, 1659916800, 1660003200, 1660003200, 
    1660003200, 1660003200, 1660089600, 1660089600, 1660089600, 
    1660089600, 1660176000, 1660176000, 1660176000, 1660176000, 
    1660262400, 1660262400, 1660262400, 1660262400, 1660348800, 
    1660348800, 1660348800, 1660348800, 1660435200, 1660435200, 
    1660435200, 1660435200, 1660521600, 1660521600, 1660521600, 
    1660521600, 1660608000, 1660608000, 1660608000, 1660608000, 
    1660694400, 1660694400, 1660694400, 1660694400, 1660780800, 
    1660780800, 1660780800, 1660780800, 1660867200, 1660867200, 
    1660867200), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
    v9 = structure(c(1658793600, 1658880000, 1658880000, 1658880000, 
    1658880000, 1658966400, 1658966400, 1658966400, 1658966400, 
    1659052800, 1659052800, 1659052800, 1659052800, 1659139200, 
    1659139200, 1659139200, 1659139200, 1659225600, 1659225600, 
    1659225600, 1659225600, 1659312000, 1659312000, 1659312000, 
    1659312000, 1659398400, 1659398400, 1659398400, 1659398400, 
    1659484800, 1659484800, 1659484800, 1659484800, 1659571200, 
    1659571200, 1659571200, 1659571200, 1659657600, 1659657600, 
    1659657600, 1659657600, 1659744000, 1659744000, 1659744000, 
    1659744000, 1659830400, 1659830400, 1659830400, 1659830400, 
    1659916800, 1659916800, 1659916800, 1659916800, 1660003200, 
    1660003200, 1660003200, 1660003200, 1660089600, 1660089600, 
    1660089600, 1660089600, 1660176000, 1660176000, 1660176000, 
    1660176000, 1660262400, 1660262400, 1660262400, 1660262400, 
    1660348800, 1660348800, 1660348800, 1660348800, 1660435200, 
    1660435200, 1660435200, 1660435200, 1660521600, 1660521600, 
    1660521600, 1660521600, 1660608000, 1660608000, 1660608000, 
    1660608000, 1660694400, 1660694400, 1660694400, 1660694400, 
    1660780800, 1660780800, 1660780800, 1660780800, 1660867200, 
    1660867200, 1660867200, 1660867200, 1660953600, 1660953600, 
    1660953600), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
    v10 = structure(c(1658793600, 1658880000, 1658880000, 1658880000, 
    1658880000, 1658966400, 1658966400, 1658966400, 1658966400, 
    1659052800, 1659052800, 1659052800, 1659052800, 1659139200, 
    1659139200, 1659139200, 1659139200, 1659225600, 1659225600, 
    1659225600, 1659225600, 1659312000, 1659312000, 1659312000, 
    1659312000, 1659398400, 1659398400, 1659398400, 1659398400, 
    1659484800, 1659484800, 1659484800, 1659484800, 1659571200, 
    1659571200, 1659571200, 1659571200, 1659657600, 1659657600, 
    1659657600, 1659657600, 1659744000, 1659744000, 1659744000, 
    1659744000, 1659830400, 1659830400, 1659830400, 1659830400, 
    1659916800, 1659916800, 1659916800, 1659916800, 1660003200, 
    1660003200, 1660003200, 1660003200, 1660089600, 1660089600, 
    1660089600, 1660089600, 1660176000, 1660176000, 1660176000, 
    1660176000, 1660262400, 1660262400, 1660262400, 1660262400, 
    1660348800, 1660348800, 1660348800, 1660348800, 1660435200, 
    1660435200, 1660435200, 1660435200, 1660521600, 1660521600, 
    1660521600, 1660521600, 1660608000, 1660608000, 1660608000, 
    1660608000, 1660694400, 1660694400, 1660694400, 1660694400, 
    1660780800, 1660780800, 1660780800, 1660780800, 1660867200, 
    1660867200, 1660867200, 1660867200, 1660953600, 1660953600, 
    1660953600), class = c("POSIXct", "POSIXt"), tzone = "UTC")), row.names = c(NA, 
100L), class = "data.frame")


Solution

  • table can be used to determine how many columns each date appears in:

    df <- setNames(data.frame(table(unlist(lapply(data, unique)))), c("date", "count"))
    df
    #>          date count
    #> 1  1658361600     1
    #> 2  1658448000     1
    #> 3  1658534400     3
    #> 4  1658620800     3
    #> 5  1658707200     5
    #> 6  1658793600     7
    #> 7  1658880000     7
    #> 8  1658966400     8
    #> 9  1659052800     9
    #> 10 1659139200     9
    #> 11 1659225600     9
    #> 12 1659312000     9
    #> 13 1659398400     9
    #> 14 1659484800     9
    #> 15 1659571200     9
    #> 16 1659657600     9
    #> 17 1659744000     9
    #> 18 1659830400     9
    #> 19 1659916800     9
    #> 20 1660003200     9
    #> 21 1660089600     8
    #> 22 1660176000     8
    #> 23 1660262400     8
    #> 24 1660348800     8
    #> 25 1660435200     8
    #> 26 1660521600     8
    #> 27 1660608000     7
    #> 28 1660694400     7
    #> 29 1660780800     6
    #> 30 1660867200     6
    #> 31 1660953600     4
    #> 32 1661040000     2
    #> 33 1661126400     2
    #> 34 1661212800     1
    #> 35 1665705600     1
    #> 36 1665792000     1
    #> 37 1665878400     1
    #> 38 1665964800     1
    #> 39 1666051200     1
    #> 40 1666137600     1
    #> 41 1666224000     1
    #> 42 1666310400     1
    #> 43 1666396800     1
    #> 44 1666483200     1
    #> 45 1666569600     1
    #> 46 1666656000     1
    #> 47 1666742400     1
    #> 48 1666828800     1
    #> 49 1666915200     1
    #> 50 1667001600     1
    #> 51 1667088000     1
    

    It doesn't look like there are any dates that appear in all ten columns.