Home > Back-end >  Matrix multiplication from the data frame in R
Matrix multiplication from the data frame in R

Time:07-15

I'm studying matrix multiplication in R. I want to do matrix multiplication from the data frame. Let's say I have df and beta as follows:

df <- data.frame(one = c(1,1,1,1,1),
                 x1=c(21,34,24,35,42),
                 x2=c(32,24,13,21,35))
beta<-c(1,2,2)

df is a 5 by 3 matrix and beta is 3 by 1 matrix. I want to multiply beta to df to get a 5 by 1 column matrix. Usually, using the standard multiplication, the code should be

df%*           
  • Related