I have a dataframe that looks like this:
a b c d
1 0 1 1
.5 1 1 0
.5 1 .5 .5
0 0 1 NA
0 1 0 1
I want to check if any of the 3 columns contain the same value so the output would look like this:
val. count
1 1
.5 1
I am trying to do this for any n number of columns. So far, I am just hard coding each scenario by using ifelse statements as shown below:
t <- data %>%
select(ivs) %>%
mutate(all = ifelse(a == 1 &
b == 1 &
c == 1 &
d == 1, 1 , 0),
any_3 = ifelse((a == 1 &
b == 1 &
c == 1 &
d == 0) |
(a == 1 &
b == 1 &
c == 0 &
d == 1) |
(a == 0 &
b == 1 &
c == 1 &
d == 1)|
(a == 0 &
b == 1 &
c == 1 &
d == 1), 1, 0 ) )
I'm hoping there is a better way to do this. Thank you!