
我试图使用filter()函数过滤数据中的数据,但是我得到了一个错误:
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)(头(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")发布于 2022-01-12 19:49:32
看起来您的数据类型是混合的。datacol变量的类型是'factor‘,而不是'date’类型。您可以在class = "factor"的dput部分看到这一点。
structure(list(datecol = structure(1:6, .Label = c("2021-10-01",
...
"2022-01-10"), class = "factor"
...对于您的比较(date(datecol)>='2021-10-01'),您似乎正在尝试将datacol列转换为日期类型(注意,右边是一个字符串)。
在R中,转换数据类型的函数都从as.开始。因此,您可能需要的是as.Date或as.character,而不仅仅是date。
发布于 2022-01-12 23:08:36
正如在Simon.S.A.'s answer中所说的,日期列属于"factor"类。这可以从任何一个
str(ios_fb_result)
#'data.frame': 6 obs. of 4 variables:
# $ datecol : Factor w/ 102 levels "2021-10-01","2021-10-02",..: 1 2 3 4 5 6
# $ response : num 1124 965 1030 1324 1377 ...
# $ cum.response: num 1124 2089 3119 4443 5820 ...
# $ point.pred : num 1716 1609 1734 1716 1645 ...
class(ios_fb_result$datecol)
#[1] "factor"所以你所要做的就是强迫"Date"类在管道中。并删除对date()的调用。
library(dplyr)
ios_fb_result1 <- ios_fb_result %>%
mutate(datecol = as.Date(as.character(datecol))) %>%
filter(datecol >= '2021-10-01' & datecol < '2021-12-23')https://stackoverflow.com/questions/70684714
复制相似问题