I have this code:
edge_data$newly.exposedday1="No"
edge_data$newly.exposedday1= if (edge_data$Stats.day1=="E"& edge_data$from==Infected.Person) {
edge_data$newly.exposedday1==edge_data$to
} else if (edge_data$Stats.day1=="E"& edge_data$to==Infected.Person) {
edge_data$newly.exposedday1=edge_data$from
}
This is the dataset:
edge_data <- structure(list(time_start = c(1, 1, 1, 1, 1, 1), time_end = c(2, 2, 2, 2, 2, 2), Person.1 = c(1558L, 1560L, 1567L, 1632L, 1632L, 1673L), Person.2 = c(1567L, 1570L, 1574L, 1818L, 1866L, 1698L ), attrs = c("3B-3B", "3B-3B", "3B-3B", "4B-4B", "4B-4B", "1B-1B" ), temp_id = c(1L, 1L, 1L, 1L, 1L, 1L), temp_ing = c(1, 1, 1, 1, 1, 1), from = c(59L, 60L, 64L, 86L, 86L, 103L), to = c(64L, 65L, 67L, 191L, 215L, 116L), Stats.day1 = c("Susceptible", "Susceptible", "Susceptible", "Susceptible", "Susceptible", "Susceptible")), row.names = c(NA, 6L), class = "data.frame")
time_start time_end Person.1 Person.2 attrs temp_id temp_ing from to Stats.day1
1 1 2 1558 1567 3B-3B 1 1 59 64 Susceptible
2 1 2 1560 1570 3B-3B 1 1 60 65 Susceptible
3 1 2 1567 1574 3B-3B 1 1 64 67 Susceptible
4 1 2 1632 1818 4B-4B 1 1 86 191 Susceptible
5 1 2 1632 1866 4B-4B 1 1 86 215 Susceptible
6 1 2 1673 1698 1B-1B 1 1 103 116 Susceptible
What I want it to do is change the edge_data$newlyexposedday1 column in the dataframe to either the ID in the from column, or the ID in the to column, and this would be determined by if the infected person was the to person, or the from person. In other words, I want the new column to have the person that wasn't the infected person. Any help would be appreciated. Thanks.