[R] diagonal matrix construction

Spencer Graves spencer.graves at pdf.com
Wed Oct 13 05:30:02 CEST 2004


      Did you try working the examples in the "diag" documentation, one 
of which is as follows: 

 >      diag(10,3,4) # guess what?
     [,1] [,2] [,3] [,4]
[1,]   10    0    0    0
[2,]    0   10    0    0
[3,]    0    0   10    0

(R 1.9.1 for Windows). 

      The R syntax expects "three" in that context to be an argument of 
the function "diag".  If you want a 7x7 identity matrix, try diag(7).  
If you want something else, please study the examples in the 
documentation for "diag".  If that is not adequate, let us know. 

      hope this helps.  spencer graves

Chris Ryan wrote:

>Hi, 
> 
>I have worked long and hard and looked in the manuals and am having a hard time constructing a diagonal matrix.  I can get the diagonals out of a matrix but can't construct the matrix with just the diagonals.  I have been on the web site and manuals and I think that it says to use:
> 
>dsj <- diag (three = 1, nrow, ncol = 7)                           three is the name of my matrix and dsj is where I'm trying to put it but it comes back:  
> 
>unused argument(s) (three ...)
>every time that I try it.  
> 
>Am I doing something wrong in trying to make this matrix?
> 
>Thank you very much for your time, Chris Ryan
> 
> 
>Christopher W. Ryan
>Black Bear Project Leader
>West Virginia Division of Natural Resources
>Capitol Complex, Bldg 3, Rm 824
>Charleston, WV 25305
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at 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
>  
>

-- 
Spencer Graves, PhD, Senior Development Engineer
O:  (408)938-4420;  mobile:  (408)655-4567




More information about the R-help mailing list