I'm quite new in R so please forgive me if I don't use the right vocabulary. I am currently dealing with a dataset where I have a few dummy variables. The problem is that for some rows more than 1 dummy variable has a value of 1. If this is the case I would like to set the next dummy variable to NA.
I would like to try something but I don't know how to start. It would be amazing if someone could help me.
Thanks in advance!
Current data
df <- structure(list(Dum_1 = c(1L, NA, NA), Dum_2 = c(NA, 1L, NA),
Dum_3 = c(NA, 1L, 1L)), row.names = c(NA, -3L), class = c("tbl_df",
"tbl", "data.frame"))
# A tibble: 3 x 3
Dum_1 Dum_2 Dum_3
<int> <int> <int>
1 1 NA NA
2 NA 1 1
3 NA NA 1
Expected output
# A tibble: 3 x 3
Dum_1 Dum_2 Dum_3
<int> <int> <int>
1 1 NA NA
2 NA 1 NA
3 NA NA 1