更新时间:2023-01-19 14:58:36
dplyr :: filter
的文档说。 ..与基本子集不同,条件条件为NA的行将被删除。
The documentation for dplyr::filter
says... "Unlike base subsetting, rows where the condition evaluates to NA are dropped."
NA!= str
的值为 NA
,因此被过滤器
丢弃。
NA != "str"
evaluates to NA
so is dropped by filter
.
!grepl( str,NA)
返回 TRUE
,因此保留。
如果您希望过滤器
保持 NA
,则可以执行 filter(is.na(col)| col!= str)
If you want filter
to keep NA
, you could do filter(is.na(col)|col!="str")