I have a dataset, "data" where every few adjacent rows has the same "id", a parameter in the dataset. I have another dataset, "otherData", with the same id values, but only one row per id value. The order of the id's are the same in both datasets.
I want to copy a column "newColumn" from otherData to data, mapping it based on the id value. This is what I currently have:
data$newColumn[data$id == id, ] <- otherData[otherData$id == id, ]$newColumn
Simply merge the two dataframes but filter columns in
otherData to join id key and newColumn:
newData <- merge(data, otherData[c("id", "newColumn")], by=c("id"))