Reputation: 241
I have the following data:
x y z
A 0 0
B 1 0
C 0 2
D 1 1
E 2 0
F 2 3
G 1 3
H 0 0
I 3 3
I want to automatically filter out from this dataset all the rows where 'y' and 'z' assumes 0 values at the same time using dplyr (namely I want to exclude A and H only)
Upvotes: 0
Views: 50
Reputation: 13680
Using dplyr
:
library(dplyr)
df %>%
filter(y != 0 | z != 0)
# x y z
# 1 B 1 0
# 2 C 0 2
# 3 D 1 1
# 4 E 2 0
# 5 F 2 3
# 6 G 1 3
# 7 I 3 3
Upvotes: 1
Reputation: 734
If your dataset is stored in a data.frame
called df
You can with dplyr
do this :
filter(df, !y == 0, !z == 0)
which will return :
x y z
B 1 0
C 0 2
D 1 1
E 2 0
F 2 3
G 1 3
I 3 3
Upvotes: 0