Reputation: 1
data.frame = completed
unique_ID Var1 Var2 Var3
1000820-1 FALSE FALSE FALSE
1000820-2 FALSE FALSE TRUE
1000823-1 FALSE TRUE FALSE
1000823-2 FALSE FALSE TRUE
1000823-3 FALSE FALSE TRUE
1000825-49 TRUE FALSE FALSE
1000830-1 FALSE TRUE FALSE
1000830-2 FALSE FALSE TRUE
How do I choose those uniqueID with all variables are FALSE ?
I.e output:
unique_ID Var1 Var2 Var3
1000820-1 FALSE FALSE FALSE
1000825-49 FALSE FALSE FALSE
Upvotes: 0
Views: 37
Reputation: 6441
One Solution would be this
df[rowSums(df[2:4]) == 0,]
unique_ID Var1 Var2 Var3
1 1000820-1 FALSE FALSE FALSE
TRUE
and FALSE
are counted as 1
and 0
, so rowSums
gives you the number of TRUE
.
Alternative with dplyr
-package:
library(dplyr)
df %>% filter_all(all_vars(. != TRUE))
unique_ID Var1 Var2 Var3
1 1000820-1 FALSE FALSE FALSE
Upvotes: 2