I ran into this simple issue but could not figure out why. filter
for the exact date returned nothing. A reprex is below
library(dplyr)
library(lubridate)
packageVersion("dplyr")
#> [1] '1.0.10'
packageVersion("lubridate")
#> [1] '1.9.0'
DF <- structure(list(Date = structure(c(11224.5033, 11224.5033, 11224.5033,
11224.5033, 11224.5033, 11224.5033, 11224.5033, 11224.5033, 11224.5033,
11224.5033, 11224.5033, 11224.5033, 11224.5033, 11224.5033, 11225.5057,
11225.5057, 11225.5057, 11225.5057, 11225.5057, 11225.5057, 11225.5057,
11225.5057, 11225.5057, 11225.5057, 11225.5057, 11225.5057, 11225.5057,
11225.5057), class = "Date"),
Z = c(42.65, 42.34, 41.73, 41.12,
40.51, 39.9, 39.29, 38.68, 38.07, 37.46, 36.85, 36.24, 35.63,
35.02, 42.65, 42.34, 41.73, 41.12, 40.51, 39.9, 39.29, 38.68,
38.07, 37.46, 36.85, 36.24, 35.63, 35.02),
Temp = c(7.65, 7.58,
7.53, 7.54, 7.54, 7.49, 7.2, 6.58, 6.67, 6.68, 6.71, 6.86, 7.26,
8.38, 7.62, 7.54, 7.48, 7.48, 7.48, 7.48, 7.48, 7.45, 6.64, 6.61,
6.62, 6.75, 7.11, 8.28)),
row.names = c(NA, -28L), class = "data.frame")
DF
#> Date Z Temp
#> 1 2000-09-24 42.65 7.65
#> 2 2000-09-24 42.34 7.58
#> 3 2000-09-24 41.73 7.53
#> 4 2000-09-24 41.12 7.54
#> 5 2000-09-24 40.51 7.54
#> 6 2000-09-24 39.90 7.49
#> 7 2000-09-24 39.29 7.20
#> 8 2000-09-24 38.68 6.58
#> 9 2000-09-24 38.07 6.67
#> 10 2000-09-24 37.46 6.68
#> 11 2000-09-24 36.85 6.71
#> 12 2000-09-24 36.24 6.86
#> 13 2000-09-24 35.63 7.26
#> 14 2000-09-24 35.02 8.38
#> 15 2000-09-25 42.65 7.62
#> 16 2000-09-25 42.34 7.54
#> 17 2000-09-25 41.73 7.48
#> 18 2000-09-25 41.12 7.48
#> 19 2000-09-25 40.51 7.48
#> 20 2000-09-25 39.90 7.48
#> 21 2000-09-25 39.29 7.48
#> 22 2000-09-25 38.68 7.45
#> 23 2000-09-25 38.07 6.64
#> 24 2000-09-25 37.46 6.61
#> 25 2000-09-25 36.85 6.62
#> 26 2000-09-25 36.24 6.75
#> 27 2000-09-25 35.63 7.11
#> 28 2000-09-25 35.02 8.28
str(DF)
#> 'data.frame': 28 obs. of 3 variables:
#> $ Date: Date, format: "2000-09-24" "2000-09-24" ...
#> $ Z : num 42.6 42.3 41.7 41.1 40.5 ...
#> $ Temp: num 7.65 7.58 7.53 7.54 7.54 7.49 7.2 6.58 6.67 6.68 ...
selected_date <- "2000-09-24"
DF %>%
filter(Date == selected_date)
#> [1] Date Z Temp
#> <0 rows> (or 0-length row.names)
DF %>%
filter(Date == as.Date(selected_date))
#> [1] Date Z Temp
#> <0 rows> (or 0-length row.names)
DF %>%
filter(Date == ymd(selected_date))
#> [1] Date Z Temp
#> <0 rows> (or 0-length row.names)