I have a list of dataframes. I would like to filter each df base on the value of certain variables that are included in dtvarlst. Is it possible to use map() method to loop through the whole list and get what I want? Could anyone guide me on this? Or if you know any other way to do it.
The data and my attempt code:
df1<- structure(list(ID = c(1, 2, 3, 4, 5), STDT = structure(c(1751328000,
1751414400, 1751500800, 1751587200, 1751673600), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), Grade = c(98, 56, 32, 88, 75), ENDT = structure(c(1751760000,
1751846400, 1751932800, 1752019200, 1752105600), class = c("POSIXct",
"POSIXt"), tzone = "UTC")), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -5L))
df2 <-structure(list(ID = c(2, 5, 9, 7, 6), STDT1 = structure(c(1750809600,
1750896000, 1750982400, 1751068800, 1751155200), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), RFDT2 = structure(c(1751328000, 1751414400,
1751500800, 1751587200, 1751673600), class = c("POSIXct", "POSIXt"
), tzone = "UTC")), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-5L))
lst1 <- list(df1, df2)
dtvar <- c("STDT", "ENDT")
lst2<- map(lst1,
function(.x)
.x <-.x %>%
filter(any_of(one_of(dtvar))<=ymd("2025-07-03")) # Did not work#
)