1

How can I select the rows, which at least once have value 1 in all 4 columns? or have only 0 through all columns?

1 Answer 1

0

We can use filter with if_any/if_all

library(dplyr)
df1 %>%
    filter(if_any(everything(), ~ .== 1)|if_all(everything(), ~ . == 0))

Or with base R

df1[(rowSums(df1 == 1) > 0) | (rowSums(df1 == 0) == ncol(df1)),]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.