使用dplyr过滤特定的情况 [英] Filter a specific case using dplyr
本文介绍了使用dplyr过滤特定的情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
A< - c(1,1,1,1,2, 2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5)
B <-C( 1,1,2,1,2,1,2,3,2,3,3,4,4,3,2,3,3,4,4,5,4,4,5,5,5)
C< - c(1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0, 1,0,0,0,0)
数据< - data.frame(A,B,C)
然后我创建以下向日葵图
库(zoo)
数据$ F = na.locf(数据$ F)
数据$ G = ifelse(Data $ C == 1,NA,数据$ B)
向日葵图(Data $ G〜Data $ F,
main =Flower_plot ,
xlab =B value where C == 1,
ylab =B value where C == 0,
size = 0.25,cex.lab = 1.3,mgp = c (2.3,1,0))
当我们看情节时,我们要删除一些的数据。
我们要删除C = 1和B = 3的位置,C = 0和B = 4的数据
我已经尝试过这样的事情
library(dplyr)
Data_cleaned< - Data%>%
group_by(C)%>%
filter(rm(B == 4 [A == 3& C == 0]))
解决方案
/ p>
Data_cleaned< - Data%>%
过滤器(!(B == 4& A == 3 & C == 0))
!
意思是 NOT
- 否定结果。
Say I have the following generic data
A <- c(1,1,1,1,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5)
B <- c(1,1,2,1,2,1,2,3,2,3,3,4,4,3,2,3,3,4,4,5,4,4,5,5,5)
C <- c(1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0)
Data <- data.frame(A,B,C)
Then I create the following sunflower plot
library(zoo)
Data$F = ifelse(Data$C==1,Data$A,NA)
Data$F = na.locf(Data$F)
Data$G = ifelse(Data$C==1,NA,Data$B)
sunflowerplot(Data$G ~ Data$F,
main = "Flower_plot",
xlab = "B value where C==1",
ylab = "B value where C==0",
size = 0.25, cex.lab = 1.3, mgp = c(2.3,1,0))
And when we look at the plot, we want to remove some of the data.
We want to remove where for a C=1 and B=3, the data where C=0 and B=4
I have tried something like this
library(dplyr)
Data_cleaned <- Data %>%
group_by(C) %>%
filter(rm(B==4[A==3 & C==0]))
解决方案
Try this:
Data_cleaned <- Data %>%
filter(!(B==4 & A==3 & C==0))
!
means NOT
- negates the results.
这篇关于使用dplyr过滤特定的情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文