Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
dplyr中的条件滤波_R - Fatal编程技术网

dplyr中的条件滤波

dplyr中的条件滤波,r,R,我有一个数据帧,我正在尝试一些我不知道如何实现的条件格式。 运行下面的示例代码后(生成数据帧X): x我们可以在filter中使用any进行groupby library(dplyr) x %>% group_by(A) %>% filter(any(B == 'X' & C == 20)) # A tibble: 3 x 3 # Groups: A [1] # A B C # <fct> <fct> &l

我有一个数据帧,我正在尝试一些我不知道如何实现的条件格式。 运行下面的示例代码后(生成数据帧X):


x我们可以在
filter
中使用
any
进行
groupby

library(dplyr)
x %>% 
   group_by(A) %>%
   filter(any(B == 'X' & C == 20))
# A tibble: 3 x 3
# Groups:   A [1]
#  A     B         C
#  <fct> <fct> <dbl>
#1 A     X        20
#2 A     Y        30
#3 A     Z        40

我们可以使用
any
filter
中进行
groupby

library(dplyr)
x %>% 
   group_by(A) %>%
   filter(any(B == 'X' & C == 20))
# A tibble: 3 x 3
# Groups:   A [1]
#  A     B         C
#  <fct> <fct> <dbl>
#1 A     X        20
#2 A     Y        30
#3 A     Z        40
library(dplyr)
x %>% 
   group_by(A) %>%
   filter(any(B == 'X' & C == 20))
# A tibble: 3 x 3
# Groups:   A [1]
#  A     B         C
#  <fct> <fct> <dbl>
#1 A     X        20
#2 A     Y        30
#3 A     Z        40
x %>% 
   group_by(A) %>%
   filter(sum(B == 'X' & C == 20) > 0)