Communities for your favorite technologies. Explore all Collectives
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
How can I select the rows, which at least once have value 1 in all 4 columns? or have only 0 through all columns?
We can use filter with if_any/if_all
filter
if_any/if_all
library(dplyr) df1 %>% filter(if_any(everything(), ~ .== 1)|if_all(everything(), ~ . == 0))
Or with base R
base R
df1[(rowSums(df1 == 1) > 0) | (rowSums(df1 == 0) == ncol(df1)),]
Add a comment
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.