Hello,
I am looking for a simple way to solve the following problem with dplyr syntax (mutate probably?). Essentially, I want the Origin
column compared to the other Destination_x
columns and when Origin
is 5 then the corresponding value on that row in Destination_5
should be changed to 0. The same should happen in the second example, if it sees 7 for the second row then the second value in Destination_7
should be changed to 0.
df <- data.frame(
Origin = c(5,7,3,12,2,6,8,5,8,
9,12,3,12,9,4,4,2,4,4),
Destination_1 = c(1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1),
Destination_2 = c(1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1),
Destination_3 = c(1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1),
Destination_4 = c(1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1),
Destination_5 = c(1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1),
Destination_6 = c(1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1),
Destination_7 = c(1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1),
Destination_8 = c(1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1),
Destination_9 = c(1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1),
Destination_10 = c(1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1),
Destination_11 = c(1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1),
Destination_12 = c(1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1),
Destination_13 = c(1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1)
)