On Tue, 7 Sep 2010 06:26:09 -0700 (PDT) "Peng, C" <cpeng....@gmail.com> wrote:
> > This this what you want? > > > A=matrix(1:16,ncol=4) > > A > [,1] [,2] [,3] [,4] > [1,] 1 5 9 13 > [2,] 2 6 10 14 > [3,] 3 7 11 15 > [4,] 4 8 12 16 > > diag(A[1:4,4:1]) > [1] 13 10 7 4 Or > A[cbind(1:4,4:1)] [1] 13 10 7 4 one character more to type, but could be more efficient for large A :) Cheers, Berwin ========================== Full address ============================ Berwin A Turlach Tel.: +61 (8) 6488 3338 (secr) School of Maths and Stats (M019) +61 (8) 6488 3383 (self) The University of Western Australia FAX : +61 (8) 6488 1028 35 Stirling Highway Crawley WA 6009 e-mail: ber...@maths.uwa.edu.au Australia http://www.maths.uwa.edu.au/~berwin ______________________________________________ R-help@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.