See the FAQ: How to do a minimal reproducible example reprex
for beginners for possibly more useful answers.
Creating an index of product names shared by two data frames is doable, but contortions may be required if both datasets are not in tidy
format. In particular, to use the following, make sure that the first table or its copy has only the two columns, product
and id
or you'll carry over data you may not wish to.
set.seed(137)
df1 <- data.frame(product = sample(LETTERS,25),
id = sample(1:25,25))
set.seed(137)
df2 <- data.frame(product = sample(LETTERS,50, replace = TRUE))
head(df1)
#> product id
#> 1 B 1
#> 2 H 16
#> 3 O 23
#> 4 F 3
#> 5 X 22
#> 6 G 24
head(df2)
#> product
#> 1 B
#> 2 H
#> 3 O
#> 4 F
#> 5 O
#> 6 G
head(dplyr::left_join(df2,df1,by="product"))
#> product id
#> 1 B 1
#> 2 H 16
#> 3 O 23
#> 4 F 3
#> 5 O 23
#> 6 G 24