I have 2 dummy variables
physical_violence
andsexual_violence
.
I tried to combine them with the ifelse()
function and the |
-operator to create a dummy variable, which returns 1 if at least one violence has occured.
The following approach outputs different results:
df <- mutate(df, physical_violence = iffelse(e03bidummy == 1 | e03cidummy == 1 |
e03didummy == 1 | e03eidummy == 1 | e03fidummy == 1 |
e03gidummy == 1 | e03hidummy == 1 | e03iidummy == 1 |
e03jidummy == 1, 1, 0))
df <- mutate(df, sexual_violence = ifelse(e04aidummy == 1 |
e04bidummy == 1 | e04cidummy == 1 | e04didummy == 1, 1, 0))
The code for the dummy combining the two variables above:
df <- mutate(df, physical_sexual_violence =
ifelse(physical_violence == 1 | sexual_violence == 1, 1, 0))
The results I got from the are:
table(df$physical_sexual_violence)
: # 875 "yes", 26.614 "no"`
This is contradictionary to:
table(df$physical_violence)
: # 846 "yes" (3.07%) and 26.643 "no"table(df$sexual_violence)
# 634 "yes" and 26.855 "no".
I expect 1.480 cases of violence.
Could anyone please help me identify what am I doing wrong?