[R] Correlation Matrix

Sundar Dorai-Raj sundar.dorai-raj at PDF.COM
Fri Oct 8 13:59:49 CEST 2004



Vito Ricci wrote:

> Hi,
> 
> I'm dealing with a datamining analysis: I've a lot of
> categories of product sold per week (n. week =26, n.
> categories about 50.
> my dataframe is like this:
> 
>   Settimana ALIMENTI..ALTRI. ALIMENTI.APROTEICI
> 1          1                3                 19
> 2          2                2                  0
> 3          3                1                 22
> 4          4                2                  6
> 
> I computed correlation coefficents among categories
> having a correlation matrix (53X53). Now I will
> extract from this matrix only significative
> correlations, or, in alternative correlations >0.5 and
> <-0.5, excluding  the other, and put this coefficients
> in a dataframe.
> 
> I'm looking for significative correlations among
> categories.
> 
> Is someone could help me? Many thanks in advance.
> Is also someone using R for dataminig analysis like
> me?
> 
> Vito
> 

Assuming `x' is your data above, how about the following:

r <- cor(x)
y <- which(lower.tri(r), TRUE)
z <- data.frame(row = rownames(r)[y[, 1]],
                 col = colnames(r)[y[, 2]],
                 cor = r[y])
subset(z, abs(cor) > 0.5)

#                row       col        cor
# 1 ALIMENTI..ALTRI. Settimana -0.6324555

--sundar




More information about the R-help mailing list