Hi Krys,
Please also cc all you responses to the list, keeping the conversation
in the archives. The following code might be of help to you:
set.seed(1)
bla = matrix(runif(10000), 10, 10)
colnames(bla) = LETTERS[1:ncol(bla)]
cor_bla = cor(bla, method = "spearman")
# Assign NA to all values below 0.7 or equal to 1
cor_bla[cor_bla < 0.7 | cor_bla == 1] = NA
# Are there any variables that have a correlation with another variable
# that is not NA, those are the ones you want
apply(cor_bla, 2, function(x) any(!is.na(x)))
# Show the names of the columns that fit the conditions
rownames(cor_bla)[apply(cor_bla, 2, function(x) any(!is.na(x)))]
cheers,
Paul
Paul Hiemstra wrote:
Hi,
I'm not sure I understand what you want. This would have been easier
if you had provided a reproducible example. See the following code:
bla = matrix(runif(10000), 10, 10)
cor_bla = cor(bla, method = "spearman")
Now what do you want to select. All the variables that have a
correlation higher than 0.8 with any of the other variables, excluding
themselves? Or a correlation higher than 0.8 in contrast to one of the
variables, e.g. the third variable?
cheers,
Paul
Krystyna Golabek wrote:
Dear R users,
Simple question. Can anyone help with the code that would allow me to
view only the variables who's correlation output is >0.8?
This is the code I'm using to date
cor(data, method="spearman")
Kind regards
Krys
--------------------------------------------
_________________________________________________________________
Save time by using Hotmail to access your other email accounts.
[[alternative HTML version deleted]]
______________________________________________
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.
--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone: +3130 274 3113 Mon-Tue
Phone: +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul
______________________________________________
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.