Weighted rowSums of a matrix
问题 I have a matrix like this: I would like to sum every value of a single row but weighted. Example: Given a specific row, the sum would be: S = x1 * loan + x2 * mortdue + x3 * value + ... x1, x2, x3, ... are predefined values. I tried rowSums() and things like that but I have not been able to figure out how to do it properly. 回答1: You are looking for a matrix-vector multiplication. For example, if you have a matrix: set.seed(0) A <- matrix(round(rnorm(9), 1), 3) # [,1] [,2] [,3] #[1,] 1.3 1.3