;>> 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
>>>
> -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
On Tue, Jul 19, 2011 at 17:34, Nordlund, Dan (DSHS/RDA)
wrote:
>> -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
>>
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
>
> H
Hi R-Help!
I am trying to find a nicer way of extracting all the "complete" diagonals
of a matrix. I am working with very large matrices that have many more rows
than columns. I want to be able to extract each of the diagonals that are
as long as the number of columns in the matrix. I have writ
6 matches
Mail list logo