I have a data.frame called "trajectory", where I have 2 rows with the same meaning but named opposite. To put you in context, those columns represent line names (i.e. "%%EDH_WSN"). Lines can be named following one direction or the opposite. That is the reason why some lines are named one way, others the opposite way, but both represent the same line. For the example given below, one line way would be "WSN_%%EDH" and the opposite "%%EDH_WSN". I have already created a code that identify the names in the opposite direction and re-write them in another column to be as the other direction (trajectory$ID_Name_New), that means for the example: "%%EDH_WSN" == "WSN_%%EDH"; in my code, one of them have changed to be written the same way: "%%EDH_WSN" == "%%EDH_WSN". What I would like to do now is to calculate how many times the code has to change that names ("Trafico Enfrentado == "YES") and identify the ones written opposite way ("Which_Segment").
To expose better my issue I present a short reprex:
trayectory<-data.frame(stringsAsFactors=FALSE,
ID_Name = c("%%EDH_WSN", "%DIPA_PITES", "%DIPI_LADAT", "%DRSI_SITET",
"%200_BAKER", "%%WSN_EDH", "%PITES_DIPA", "%BAKER_200"),
ID_Name_New = c("%%EDH_WSN", "%DIPA_PITES", "%DIPI_LADAT", "%DRSI_SITET",
"%200_BAKER", "%%EDH_WSN", "%DIPA_PITES", "%200_BAKER")
)
solution<-data.frame(stringsAsFactors=FALSE,
ID_Name = c("%%EDH_WSN", "%DIPA_PITES", "%DIPI_LADAT",
"%DRSI_SITET", "%200_BAKER", "%%WSN_EDH",
"%PITES_DIPA", "%BAKER_200"),
ID_Name_New = c("%%EDH_WSN", "%DIPA_PITES", "%DIPI_LADAT",
"%DRSI_SITET", "%200_BAKER", "%%EDH_WSN",
"%DIPA_PITES", "%200_BAKER"),
Trafico_Enfrentado = c("YES", "YES", "NO", "NO", "YES", "YES", "YES", "YES"),
Which_Segment = c("%%WSN_EDH", "%PITES_DIPA", "NA", "NA",
"%BAKER_200", "%%EDH_WSN", "%DIPA_PITES",
"%200_BAKER")
)
Thanks in advance for your help!