[R] The best way for making speciall matrix

Abby Spurdle @purd|e@@ @end|ng |rom gm@||@com
Sat May 23 12:12:46 CEST 2020


This sounds like a homework question...
But... numerical linear algebra rocks...

    cbind (diag (1:3), 4:6)


On Sat, May 23, 2020 at 9:46 PM Vahid Borji <vahid.borji65 using gmail.com> wrote:
>
> Hi my friends,
>
> I want to make the below matrix in r:
>
> 1 0 0 4
>
> 0 2 0 5
>
> 0 0 3 6
>
> I used the below code:
>
> matrix(c(1,0,0,0,2,0,0,0,3,4,5,6),nrow=3)
>
> My code works. But I do not like my solution way. I am thinking to find the
> simplest way for making this matrix. Do you think my code is the simplest
> code for making this matrix? If not, could anyone writes a simpler code
> than my one?
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list