merge combines rows from two data frames using a shared key column.

Program

Play the script to attach prices to orders and add the prices.

merge_join.R
orders <- data.frame(id = c(1, 2), item = c("book", "pen"))
prices <- data.frame(item = c("book", "pen"), price = c(12, 3))
joined <- merge(orders, prices, by = "item")
total <- sum(joined$price)
cat(total, "\n", sep = "")
merge `merge` joins data frames by matching key values.
key column `by = "item"` names the column shared by both tables.
joined data The joined table contains columns from both inputs.