我正在使用R和dplyr
库对包含一列的字符data.frame执行字符串搜索。对两个字符串执行AND操作,以对位置数据进行条件测试。我在dplyr::filter
评估中出错。
str(dec2013.data)
'data.frame': 10481 obs. of 1 variable:
$ Routing.SYSID: chr "L839ITSRLX001TGU3" "L839SMARLX001TGU3"
"L839CRJRLX001TGU3" "L839BUARLX001TGU3"
dec2013.data.route1 <- data.frame()
dec2013.data.route1 <- dec2013.data %>%
filter(str_detect(Routing.SYSID,"L839" &
str_detect(Routing.SYSID,"TGU3")))
dput()
"L839CHHFNL626TGU3", "L839HPHFNL626TGU3", "L839NHBFNL626TGU3",
"L839BMQFNL626TGU3", "L839JUCFNL626TGU3", "L839KJYFNL626TGU3",
"L839KPPFNL626TGU3", "L839IWHFNL626TGU3", "L839NOFFNL626TGU3",
"L839DXQFNL626TGU3", "L839TMUFNL626TGU3", "L839RGCFNL626TGU3"
filter_impl(.data,quo)中的错误:评估错误:操作是 仅适用于数字,逻辑或复杂类型。
答案 0 :(得分:2)
您的括号是错误的。这应该起作用:
dec2013.data %>%
filter(str_detect(Routing.SYSID,"L839"), str_detect(Routing.SYSID,"TGU3"))