[R] how to creat a matrix

Henrique Dallazuanna wwwhsd at gmail.com
Fri Dec 11 17:05:35 CET 2009


Try this:

N <- 5
diag(1, N)[c(N, 1:(N - 1)),]

On Fri, Dec 11, 2009 at 1:47 PM, Moohwan Kim <kmhlmj2 at gmail.com> wrote:
> Dear R family
>
>  I am attempting to create a matrix. e.g.,
>  0 0 0 0 1
>  1 0 0 0 0
>  0 1 0 0 0
>  0 0 1 0 0
>  0 0 0 1 0
>  How could I write a R program?
>  Later I want to extend it to a N by N case.
>  Thanks in advance
>
>  best
>  Moohwan
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O




More information about the R-help mailing list