How do I convert a n*1 matrix to a n*n diagonal matrix

后端 未结 3 1170
梦如初夏
梦如初夏 2021-01-19 11:04

I have a nx1 matrix I want to convert this to a nxn diagonal matrix in R

\"matrix

3条回答
  •  天命终不由人
    2021-01-19 11:35

    If you just want to know how to do this in R, it's:

    my.matrix       <- matrix(0, nrow=4, ncol=4)
    diag(my.matrix) <- rep(0.25, 4)
    

提交回复
热议问题