2

I have a correlation matrix in R, that I want to only see numbers > 0.5. Can I change this to TRUE/FALSE depending on the number? Or can I only display the values >0.5? I've tried filtering but that doesn't work.

ETA: So I used

cors <- cor(data)

Which gave me a correlation matrix, say

    A    B    C    D
W   0.6  0.3  0.0  0.3
X   0.1  0.4  0.2  0.1
Y   0.7  0.2  0.1  0.0
Z   0.2  0.8  0.6  0.4

And now I want to easily show those values above 0.5. Let me know if you need more code!

gf7
  • 145
  • 11
  • 1
    1 ) `mat > 0.5` to get `TRUE`/`FALSE` values 2) `mat[mat <= 0.5] <- NA` to to replace values less than 0.5 to `NA`. 3) `mat[mat > 0.5]` will give you the values greater than 0.5. Is that what you need? – Ronak Shah Sep 27 '20 at 02:34
  • Can you show us some code? – Algo7 Sep 27 '20 at 02:35
  • It could be, but I'm unsure how to use it (it's saying not found). Would you do something like? 'pairs <- mat > 0.5' (The matrix is named "cors") – gf7 Sep 27 '20 at 02:51
  • 1
    Yes, so you need to replace `mat` with `cors`. Try `cors[cors <= 0.5] <- NA` – Ronak Shah Sep 27 '20 at 02:55
  • That worked! Thank you so much! – gf7 Sep 27 '20 at 03:00

0 Answers0