我有带有列的数据框。我想返回一个子数据帧,该子数据帧被多个条件从原始帧中滤除。我的第一个问题是我想按两列进行过滤:一列包含离散值,而我想过滤包含值“ Open”的行。另一列包含日期值,我想对等于给定日期的行进行复合过滤
这是我使用dplyr的过滤功能
agendaReq <- function(recTable, agendaDate)
{
openTable <- filter(recTable, recTable$reqStatus == "Open")
agendaTable <- filter(openTable, recTable$reqDate == agendaDate)
return (agendaTable)
}
但是,当我在服务器中按如下所示调用此函数时
agendaToShow <- agendaReq(recordTable_CA, Sys.Date())
我收到此错误
Warning: Error in : Result must have length 14, not 16
56: <Anonymous>
Error : Result must have length 14, not 16
原始数据帧中有16行。正确的过滤器应该给我14行。但是这个错误是什么意思?
最后,如何对离散变量和连续变量进行混合处理? (例如,根据性别,身高等进行过滤...)
谢谢
答案 0 :(得分:1)
如果没有可重现的小示例数据,很难确定它是否有效,但是您是否尝试过:
library(dplyr)
recTable %>% filter(reqStatus == "Open" & reqDate == agendaDate)
如果这不起作用,请考虑按照以下说明提供可复制的数据示例:How to make a great R reproducible example