1

I have a task to take a corps of given data and post it as a matrix and I have already done this.

Now, I have this matrix with column and row names already and I need to check whether the absolute value of entries in the matrix are more than 0.5 or not. If that is the case, this particular value and the names of column and row need to be printed.

Furthermore, the matrix in question is symmetric and the values of its diagonal are equal 1, so those don't have to be printed.

Do you have any ideas of how to realize it? Should I put these results in a matrix or in a data frame? Which of these two would be easier to realize?

Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248
  • 3
    What have you tried? Also, please post a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Ari B. Friedman Nov 14 '12 at 11:43

1 Answers1

0

An example:

set.seed(101)
x <- matrix(rnorm(100),10) 
xx <- cor(x) # correlation matrix
rownames(xx) <- colnames(xx) <- letters[1:10]

Find the combinations of interest (|r| > 0.5):

combinations <- levels(interaction(rownames(xx), colnames(xx)))
idx <- abs(xx) > 0.5
diag(idx) <- idx[upper.tri(idx)] <- FALSE
results <- data.frame(combination = combinations[idx], rho = xx[idx])

#   combination        rho
# 1         d.a -0.5739332
# 2         e.a  0.6352977
# 3         f.c  0.5977269
# 4         h.g -0.8208542
Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168