On Jul 20, 2011, at 03:42 , Peter Lomas wrote:
> Thanks very much to everyone who replied. Peter got me on my way with
> the use diag() hint, and I came with a less pretty version of Dan's
> first option almost at the same time as I got that email. Seems I
> can't avoid one for loop, but one is
> -Original Message-
> From: Peter Lomas [mailto:peter.lo...@ucalgary.ca]
> Sent: Tuesday, July 19, 2011 6:42 PM
> To: Nordlund, Dan (DSHS/RDA)
> Cc: r-help@r-project.org
> Subject: Re: [R] Taking all "complete" diagonals of a matrix
>
> Thanks very mu
Thanks very much to everyone who replied. Peter got me on my way with
the use diag() hint, and I came with a less pretty version of Dan's
first option almost at the same time as I got that email. Seems I
can't avoid one for loop, but one is better than two.
Just as a note, with this code you hav
Hi:
Does this work for you?
mydiags <- function(mat) diag(mat[seq_len(ncol(mat)), ])
# Example:
set.seed(103)
u <- matrix(rpois(200, 10), ncol = 10)
# > dim(u)
# [1] 20 10
mydiags(u)
# [1] 7 12 6 13 12 6 5 6 14 6
u[1:10, ] # as a double check
HTH,
Dennis
On Tue, Jul 19, 2011 at 2:15
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Peter Lomas
> Sent: Tuesday, July 19, 2011 2:16 PM
> To: r-help@r-project.org
> Subject: [R] Taking all "complete" diagonals of a matrix
>
> Hi R-Help!
>
> I am trying to find a
5 matches
Mail list logo