Create a matrix from a vector in R

前端 未结 1 841
时光取名叫无心
时光取名叫无心 2021-01-28 02:28

I have a vector v, and I would like to create the following matrix. How can I do this in R?

      v = c(1, 2, 3, 4)

      > m = matrix(c(1, 1, 1         


        
相关标签:
1条回答
  • 2021-01-28 03:08

    See ?matrix and the nrow, ncol, byrow arguments:

    matrix(v, nrow=4, ncol=4, byrow=TRUE)
    #     [,1] [,2] [,3] [,4]
    #[1,]    1    2    3    4
    #[2,]    1    2    3    4
    #[3,]    1    2    3    4
    #[4,]    1    2    3    4
    
    0 讨论(0)
提交回复
热议问题