I need to give name to a number based on info from a data.frame. To expose my issue I create a short reprex:
segmento_info<- data.frame(stringsAsFactors=FALSE,
ID = c(35540, 35658, 35731, 35825, 35541, 35542,
35543, 35544),
Segment_Name = c("XILTI_ARTAT", "ZAG_VBA", "ZMR_ORBIS",
"ZWN_PIREK", "VERCE_MLP.A", "VERED_BMN.A",
"VERED_WSN", "VEREV_GIMEX")
)
InfoTOChange<- data.frame(stringsAsFactors=FALSE,
ID_1 = c(35540, 35540, 35540, 35540, 35540, 35540,
35540, NA),
ID_2 = c(35658, 35731, 35825, 35541, 35542, 35543,
35544, NA),
Non_Possible_Conflict = c("TRUE", "TRUE", "TRUE", "FALSE", "FALSE",
"FALSE", "FALSE", NA),
Possible_Inicial_Conflict = c("FALSE", "FALSE", "FALSE", "TRUE", "TRUE",
"FALSE", "FALSE", NA),
Possible_End_Conflict = c("FALSE", "FALSE", "FALSE", "TRUE", "TRUE",
"FALSE", "FALSE", NA)
)
Data.frame "segmento_info" contains the info I would like to change in the other data.frame "InfoTOChange". As it can be seen in the "segmento_info" data.frame, each ID has associated a name. What I would like the code to do for me, is to asociate ID_1 and ID_2 to its original name from the "segmet_info" data.frame; that is to say:
- ID_1 is 35540, however, it´s name (searched in the "segment_info"data.frame) is XILTI_ARTAT.
- ID_2 is 35658, however, it´s name (searched in the "segment_info"data.frame) is ZAG_VBA.
All IDs (both ID_1 and ID_2) from the data.frame "InfoTOChange" are contained in the other data.frame. "InfoTOChange" has asocciated 3 rows that I would like to keep.
Therefore, solution would be:
InfoAlreadyChanged<- data.frame(stringsAsFactors=FALSE,
Segment_Name_1 = c("XILTI_ARTAT", "XILTI_ARTAT", "XILTI_ARTAT",
"XILTI_ARTAT", "XILTI_ARTAT", "XILTI_ARTAT",
"XILTI_ARTAT"),
Segment_Name_2 = c("ZAG_VBA", "ZMR_ORBIS", "ZWN_PIREK",
"VERCE_MLP.A", "VERED_BMN.A", "VERED_WSN",
"VEREV_GIMEX"),
Non_Possible_Conflict = c("TRUE", "TRUE", "TRUE", "FALSE", "FALSE",
"FALSE", "FALSE"),
Possible_Inicial_Conflict = c("FALSE", "FALSE", "FALSE", "TRUE", "TRUE",
"FALSE", "FALSE"),
Possible_End_Conflict = c("FALSE", "FALSE", "FALSE", "TRUE", "TRUE",
"FALSE", "FALSE")
)
Important to note that I have around 35832 rows in the data.frame "segmento_info" and 42778 rows in the "InfoTOChange" data.frame, that means code should be as simple as possible to reduce compiling time.
Thanks in advance for your help!