Multiply matrices in list

后端 未结 2 1411
南旧
南旧 2021-01-15 15:15

I would like to multiply multiple matrices of a list. I know that this works with a single matrix:

 x1  <- c(2,2,2,3,1,2,4,6,1,2,4)
 y1  <- c(5,4,3,3,         


        
2条回答
  •  攒了一身酷
    2021-01-15 15:52

    So generically, how do you multiply corresponding members of two lists? Suppose the matrices with values are in list1 and those with 0/1 are in list2, then one way to do it is with lapply

     answer <- lapply(seq_along(list1),FUN=function(i) list1[[i]]*list2[[i]])
    

    Your resulting matrices will be the elements of answer.

提交回复
热议问题