Re: [R] Help to make a specific matrix

From: Jose Claudio Faria <joseclaudio.faria_at_terra.com.br>
Date: Sun 10 Jul 2005 - 11:30:35 EST

Gabor Grothendieck wrote:

> On 7/9/05, Jose Claudio Faria <joseclaudio.faria@terra.com.br> wrote:
> 

>>Dear R users,
>>
>>The solution is probably simple but I need someone to point me to it.
>>How can I to generate a matrix from a numeric sequence of 1:10 like 'A' or 'B'
>>below:
>>
>>A)
>>|--------------------|
>>| 1 2 3 4 5 |
>>|--------------------|
>>| 1 | 0 |
>>| 2 | 1 0 |
>>| 3 | 2 5 0 |
>>| 4 | 3 6 8 0 |
>>| 5 | 4 7 9 10 0 |
>>|--------------------|
>>
>>B)
>>|--------------------|
>>| 1 2 3 4 5 |
>>|--------------------|
>>| 1 | 0 1 2 3 4 |
>>| 2 | 1 0 5 6 7 |
>>| 3 | 2 5 0 8 9 |
>>| 4 | 3 6 8 0 10 |
>>| 5 | 4 7 9 10 0 |
>>|--------------------|
>>
> 
> 
> Try this and see ?lower.tri
> 
> A <- matrix(0,5,5)
> A[lower.tri(A)] <- 1:10
> B <- A + t(A)

Dear Gabor,

Thank you, very much: this soluction is nice!

Best,

-- 
Jose Claudio Faria
Brasil/Bahia/UESC/DCET
Estatistica Experimental/Prof. Adjunto
mails:
  joseclaudio.faria@terra.com.br
  jc_faria@uesc.br
  jc_faria@uol.com.br
tel: 73-3634.2779

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sun Jul 10 11:35:45 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:27 EST