In my example I have a table with products that have a unique ID in Store 1 and a different (but also unique) ID in Store 2.
As a rule, the same product has always the same ID in store 1 and always the same ID in store 2. i.e. if I know only one of these variables, I should be able to fill in the remaining ones.
However, I don't have a neat reference table or list that shows which Product and IDs belong together. All I have to start with is a table with lots of gaps like this:
I would like to fill the gaps using the information that is already in the table like so:
Is there a R function that can do this or how would you go about this?
#Example data
df <- data.frame(
c(NA, "Shovel", NA, NA, "Gloves", NA),
c("W06", NA, "W06", "W11", "W11", NA),
c("EF001", "EF001", NA, NA, "EF004", "EF004")
)
colnames(df) <- c("Product", "Store1_ID", "Store2_ID")
df2 <- data.frame(
c("Shovel",NA, NA, NA, "Gloves", NA),
c(NA, "W06", "W06", "W11", "W11", NA),
c("EF001", "EF001", NA, NA, "EF004", "EF004")
)
colnames(df2) <- c("Product", "Store1_ID", "Store2_ID")