I currently have a product table and an ingredient table, as follows:
Product (actual: 13 columns, truncated for ease of explanation):
Product_code Product_name Ingredient Brand_name
A123 Product1 NA BrandA
B123 Product2 NA BrandB
C123 Product3 NA BrandC
Ingredient (actual has 2 columns, as shown):
Product_code Ingredient
A123 Ing1
A123 Ing2
B123 IngA
B123 IngB
B123 IngC
The aim is "fill in" the ingredient details for each product in the "Product" table such that it appears as such:
Combined table:
Product_code Product_name Ingredient Brand_name
A123 Product1 Ing1 BrandA
A123 Product1 Ing2 BrandA
B123 Product2 IngA BrandB
B123 Product2 IngB BrandB
B123 Product2 IngC BrandB
C123 Product3 NA BrandC
As some products have one ingredient while others have multiple, I want to be able to duplicate new rows for products with multiple ingredients (all other column values to retain the same except for the "Ingredient" column). Products without data in the "Ingredients" table will remain as "NA".
I have tried using dplyr::right_join
but it left me with "NA" values for all the other columns other than "Product_code" and "Ingredient". Hoping to get some advice on how to proceed with this. Thanks!