Hi,
Thank you very much for the help. c[lower.tri(c,diag=FALSE)] works fine for me.
Thanks again.
Kind regards,
Ezhil
--- On Fri, 11/21/08, Anup Menon <[EMAIL PROTECTED]> wrote:
> From: Anup Menon <[EMAIL PROTECTED]>
> Subject: Re: [R] Extracting diagonal matrix
> To: [
Hi Ezhil,
Maybe this will help. There might be an easier way to do this but here is
one solution.
tril <- function(A)
{
A <- as.matrix(A)
cmats <- matrix(rep(1,length(A)),dim(A)[1],dim(A)[2])
upper.tri(cmats,diag=T)
cmats[upper.tri(cmats)] <- 0
out <- A*cmats
return(out)
}
tril(correlation
You can also do it from first principles:
outer(1:100,1:100,`<`) * m
which generalizes nicely to >, <=, >=, !=, etc.
-s
On 11/21/08, Henrique Dallazuanna <[EMAIL PROTECTED]> wrote:
> See ?upper.tri and ?lower.tri.
__
R-help@r-project.o
> --- On Fri, 11/21/08, Peter Dalgaard <[EMAIL PROTECTED]> wrote:
>
> > From: Peter Dalgaard <[EMAIL PROTECTED]>
> > Subject: Re: [R] Extracting diagonal matrix
> > To: [EMAIL PROTECTED]
> > Cc: [EMAIL PROTECTED], r-help@r-project.org
> > D
Thanks. I would like to extract all the matrix entries below or above the
diagnol. diag(x) simply gives diagonal elements.
Thanks.
Kind regards,
Ezhil
--- On Fri, 11/21/08, Peter Dalgaard <[EMAIL PROTECTED]> wrote:
> From: Peter Dalgaard <[EMAIL PROTECTED]>
> Subject:
[EMAIL PROTECTED] wrote:
> Try
>
> ?diag
Or, if he really means the diagonal of a 100x100 correlation matrix,
rep(1,100)
:-)
>
> Rory Winston
> RBS Global Banking & Markets
> Office: +44 20 7085 4476
>
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Beha
Try
?diag
Rory Winston
RBS Global Banking & Markets
Office: +44 20 7085 4476
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of A Ezhil
Sent: 21 November 2008 12:28
To: r-help@r-project.org
Subject: [R] Extracting diagonal matrix
Dear All,
I have a corre
7 matches
Mail list logo