R paste matrix cells together

前端 未结 3 1558
醉酒成梦
醉酒成梦 2021-01-19 15:23

I want to paste cells of matrix together, But when I do paste(),It returns a vector. Is there a direct function for same in R?

mat <- matrix(1:4,2,2)
past         


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-01-19 15:54

    Or use sprintf withdim<-

    `dim<-`(sprintf('%d,%d', mat, mat), dim(mat))
    #      [,1]  [,2] 
    #[1,] "1,1" "3,3"
    #[2,] "2,2" "4,4"
    

提交回复
热议问题