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]]
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 at 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
If I understand correctly, you can use which( ,arr.ind=TRUE): Assuming that you start with a data frame, dat <- as.data.frame(matrix(runif(30), ncol=5)) nm <- names(dat) cormat <- cor(dat) cormat[lower.tri(cormat, diag=TRUE)] <- NA idx <- which(cormat > 0.4, arr.ind=TRUE) idx cbind(nm[idx[, "row"]], nm[idx[, "col"]]) will give you the pairs. -Peter Ehlers 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 at 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. > >