How to correct for FIlter function error in R?
I am trying to filter data in a dataframe using filter()
function but I am getting an error:
ios_fb_result1 <- ios_fb_result %>%
filter(date(datecol)>='2021-10-01' & date(datecol) < '2021-12-23')
Error: Problem with filter()` input `..1.
ℹ Input `..1` is date(datecol) == "2021-10-01".
✖ unused argument (datecol)
dput(head(ios_fb_result))
structure(list(datecol = structure(1:6, .Label = c("2021-10-01",
"2021-10-02", "2021-10-03", "2021-10-04", "2021-10-05", "2021-10-06",
"2021-10-07", "2021-10-08", "2021-10-09", "2021-10-10", "2021-10-11",
"2021-10-12", "2021-10-13", "2021-10-14", "2021-10-15", "2021-10-16",
"2021-10-17", "2021-10-18", "2021-10-19", "2021-10-20", "2021-10-21",
"2021-10-22", "2021-10-23", "2021-10-24", "2021-10-25", "2021-10-26",
"2021-10-27", "2021-10-28", "2021-10-29", "2021-10-30", "2021-10-31",
"2021-11-01", "2021-11-02", "2021-11-03", "2021-11-04", "2021-11-05",
"2021-11-06", "2021-11-07", "2021-11-08", "2021-11-09", "2021-11-10",
"2021-11-11", "2021-11-12", "2021-11-13", "2021-11-14", "2021-11-15",
"2021-11-16", "2021-11-17", "2021-11-18", "2021-11-19", "2021-11-20",
"2021-11-21", "2021-11-22", "2021-11-23", "2021-11-24", "2021-11-25",
"2021-11-26", "2021-11-27", "2021-11-28", "2021-11-29", "2021-11-30",
"2021-12-01", "2021-12-02", "2021-12-03", "2021-12-04", "2021-12-05",
"2021-12-06", "2021-12-07", "2021-12-08", "2021-12-09", "2021-12-10",
"2021-12-11", "2021-12-12", "2021-12-13", "2021-12-14", "2021-12-15",
"2021-12-16", "2021-12-17", "2021-12-18", "2021-12-19", "2021-12-20",
"2021-12-21", "2021-12-22", "2021-12-23", "2021-12-24", "2021-12-25",
"2021-12-26", "2021-12-27", "2021-12-28", "2021-12-29", "2021-12-30",
"2021-12-31", "2022-01-01", "2022-01-02", "2022-01-03", "2022-01-04",
"2022-01-05", "2022-01-06", "2022-01-07", "2022-01-08", "2022-01-09",
"2022-01-10"), class = "factor"), response = c(1124, 965, 1030,
1324, 1377, 2827), cum.response = c(1124, 2089, 3119, 4443, 5820,
8647), point.pred = c(1715.94529277584, 1609.33717991531, 1734.44307036591,
1715.59696513439, 1644.54171869339, 2151.33940525175)), row.names = c(NA,
6L), class = "data.frame")
It looks like you have mixed data types. The datacol
variable is of type 'factor' rather than of type 'date'. You can see this in the class = "factor"
part of the dput
:
structure(list(datecol = structure(1:6, .Label = c("2021-10-01",
...
"2022-01-10"), class = "factor"
...
For your comparison (date(datecol)>='2021-10-01'
) it looks like you are trying to convert the datacol
column to a date type (though note the right-hand-side is a string).
In R the functions to convert data types all start with as.
. So you are probably looking for as.Date
or as.character
rather than just date
.