[R] variables in a correlation matrix
ripley@stats.ox.ac.uk
ripley at stats.ox.ac.uk
Wed Mar 12 17:39:58 CET 2003
On Wed, 12 Mar 2003, juli g. pausas wrote:
> Hi,
> Given a correlation matrix, how can I know which variables have certain
> correlation values?
>
> aa <- matrix( rnorm(25, 1,1), 5,5)
> colnames(aa) <- c("v1", "v2", "v3", "v4", "v5")
> aacor <- cor(aa)
>
> For instance, which variables are negatively correlated?
> aacor[aacor<0] # provide the r values, but how I get the variables?
nm <- dimnames(aacor)[[1]]
cbind(nm[row(aacor)[aacor<0]], nm[col(aacor)[aacor<0]])
is one way
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list