I am trying to do a weighted sum of a bunch of columns.
I have a weightings vector where each weight correspondence to a question in mydf.
I am having slight problems. I was wondering if anyone could nudge me in the right direction
what you want to do is a weighted sum, so basically matrix algebra. To multiply a vector with a matrix, you basically need two things:
A vector and a matrix
Comfortable dimensions for matrix multiplication.
With this in mind, you can have a look at the dimensions of your vector weights. It is a 3 \times 1 "matrix". On the other hand, your matrix has three columns and 50 rows, so it is a 50 \times 3 matrix. To obtain a meaningful result, you have to first coerce your data.frame into an actual matrix with as.matrix() (or, if you have a lot of data and need faster conversion, use collapse::qM()) and second arrange them in the right way: