I know this question is an easy one however I could not find the answer anywhere.
How to filter only a part of a data frame that respect a condition x ?
For exemple if you have:
df=data.frame(c1=c("A","A","B","C","B","C","C"),c2=c(1,1,4,3,6,2,6))
I want to get rid of the rows of the df for which c1 equals "C" that do not respect the condition c2<=3 I cannot do it like this:
df[df$c1=="C",]<-dplyr::filter(df[df$c1=="C",],c2<=3)
Of course that does not work because the replacement does not have the same number of rows. What is the easy way to do this (Preferably using dplyr
)?
One thing that could work is to include an if statement in the filter function. Is that possible ?