[R] selecting for values above or within a range in the data matrix

Peter Ehlers ehlers at ucalgary.ca
Wed Dec 8 22:49:24 CET 2010


On 2010-12-08 12:03, akchong at bidmc.harvard.edu wrote:
> Hi All,
> I am new to the R program (only my 2nd day trying it out!)
> and this may seem like a really stupid question but I was
> wondering if someone could help. I have managed to calculate
> the pearson correlation coefficient for my data and now I
> have a correlation coefficient matrix with a whole slew of
> numbers. I was wondering if there is a way to only show the
> correlation coefficient values that are between +0.85 to
> +1.0 and/or -0.85 to -1.0 in the matrix table.

Maybe something like this:

  set.seed(1066)
  m <- matrix(sample(10, 20, TRUE), 5, 4)
  cm <- cor(m)
  ind <- which(abs(cm) < 0.85)
  is.na(cm) <- ind
  round(cm, 2)

Peter Ehlers

>
> Thanks in advance,
> Allen
>
> ______________________________________________
> 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.



More information about the R-help mailing list