Dear All, I have a correlation matrix of size 100 x 100 and would like to extract the diagonal matrix from it. I have used the for loop to store tha correlation values of the diagonal matrix. Is there a 'R way' of doing this? Thanks in advance. Kind regards, Ezhil
Try
?diag
Rory Winston
RBS Global Banking & Markets
Office: +44 20 7085 4476
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of A Ezhil
Sent: 21 November 2008 12:28
To: r-help at r-project.org
Subject: [R] Extracting diagonal matrix
Dear All,
I have a correlation matrix of size 100 x 100 and would like to extract the
diagonal matrix from it. I have used the for loop to store tha correlation
values of the diagonal matrix. Is there a 'R way' of doing this?
Thanks in advance.
Kind regards,
Ezhil
______________________________________________
R-help at 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.
***********************************************************************************
The Royal Bank of Scotland plc. Registered in Scotland No 90312. Registered
Office: 36 St Andrew Square, Edinburgh EH2 2YB.
Authorised and regulated by the Financial Services Authority
This e-mail message is confidential and for use by the=2...{{dropped:22}}
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.matrix)
will give you the output.
HTH
Best Regards
Anup
On Fri, Nov 21, 2008 at 7:28 AM, A Ezhil <ezhil02@yahoo.com> wrote:
> Dear All,
>
> I have a correlation matrix of size 100 x 100 and would like to extract the
> diagonal matrix from it. I have used the for loop to store tha correlation
> values of the diagonal matrix. Is there a 'R way' of doing this?
>
> Thanks in advance.
>
> Kind regards,
> Ezhil
>
> ______________________________________________
> 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.
>
[[alternative HTML version deleted]]