df <- data.frame(x=c("s1","s1","s1","s1","s2","s2","s2","s2","s3","s3","s3","s3"), y=c("g1","g2","g3","g4","g1","g2","g3","g4","g1","g2","g3","g4"), z1=c(1,2,3,2,4,5,6,6,3,2,4,NA), z2=c(NA,1,2,3,1,2,3,1,1,2,1,NA))
我想只选择那些不包含NA的组。我以为这会奏效:
columns <- c("z1", "z2")
df %>% group_by(x) %>% filter(all(!is.na(!!columns)))
但它似乎没有过滤
3条答案
按热度按时间4uqofj5v1#
一个选项是使用
across
:fkvaft9z2#
一种在
filter
中使用if_all
的方法,带有 * 列 *或使用 tidyselect
matches
owfi6suc3#
使用sjmisc包