prices <- structure(list(Year = c(2001, 2003, 2002, 2000, 2004), P1 = c(15,
8, 13, 12, 7), P2 = c(7, 10, 8, 14, 10)), row.names = c(2L, 4L,
3L, 1L, 5L), class = "data.frame")
volumes <- structure(list(Year = c(2000, 2001, 2002, 2003, 2004), V1 = c(76,
78, 55, 74, 80), V2 = c(61, 80, 77, 68, 65), V3 = c(56, 52, 91,
69, 90), V4 = c(50, 59, 51, 66, 58), V5 = c(75, 57, 57, 80, 59
)), class = "data.frame", row.names = c(NA, -5L))
lapply
purrr::reduce
prices
volumes
volumes_mult <- lapply(prices[,-1], function(p) {
cbind(Year = volumes$Year, volumes[,-1] * p)
})
reduce
*_join
Reduce
by=
suffix=
purrr::reduce(volumes_mult, dplyr::full_join, by='Year', suffix = paste0('_', names(x)))
Year V1_P1 V2_P1 V3_P1 V4_P1 V5_P1 V1_P2 V2_P2 V3_P2 V4_P2 V5_P2
1 2000 1140 915 840 750 1125 532 427 392 350 525
2 2001 624 640 416 472 456 780 800 520 590 570
3 2002 715 1001 1183 663 741 440 616 728 408 456
4 2003 888 816 828 792 960 1036 952 966 924 1120
5 2004 560 455 630 406 413 800 650 900 580 590