'How to expand table, by matching table's column against a vector?

I apologize if this question is duplicated.

There is a table prod_table looks like

      key price
1 Printer   225
2  Tablet   570
3  Laptop  1120

And vector vec

[1] "Printer" "Laptop"  "Printer" "Tablet"  "Laptop" 

What I want is, match prod_table$key with vec and expand this table.

I tried prod_table[vec,] but it did not work.

Desired output looks like

      key price
1 Printer   225
2  Laptop  1120
3 Printer   225
4  Tablet   570
5  Laptop  1120

Here is reproducible example.

prod_table <- data.frame(
  key = c("Printer", "Tablet", "Laptop"),
  price = c(225, 570, 1120)
)
vec <- c("Printer", "Laptop", "Printer", "Tablet", "Laptop")
r


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source