R Markdown

In Example TMP the first table lists the cost (per kilogram) to manufacture each of the three varieties of trail mix (bulk, standard, fancy). For example, it costs $3.69 to make one kilogram of the bulk variety. Re-compute each of these three costs and notice that the computations are linear in character.

(trailmix <- matrix(c(7,6,2,6,4,5,2,5,8),nrow=3,ncol=3))
##      [,1] [,2] [,3]
## [1,]    7    6    2
## [2,]    6    4    5
## [3,]    2    5    8
(trailmixbatch <- trailmix/15)
##           [,1]      [,2]      [,3]
## [1,] 0.4666667 0.4000000 0.1333333
## [2,] 0.4000000 0.2666667 0.3333333
## [3,] 0.1333333 0.3333333 0.5333333
(cost <-matrix(c(2.55,4.65,4.80),nrow=3,ncol=1))
##      [,1]
## [1,] 2.55
## [2,] 4.65
## [3,] 4.80
trailmixcost <- trailmixbatch %*% cost
newresult <- data.frame(trailmixcost)
newresult <- cbind(c("bulk", "standard", "fancy"),newresult)
newresult
##   c("bulk", "standard", "fancy") trailmixcost
## 1                           bulk         3.69
## 2                       standard         3.86
## 3                          fancy         4.45