Re: [R] Selecting all values smaller than X in a dataframe

From: Vladimir Eremeev <>
Date: Mon, 11 Jun 2007 05:35:38 -0700 (PDT)

Christoph Scherber-2 wrote:
> Dear R users,
> I have a correlation matrix for a dataframe called "synth", for which I
> now want to select only those cells that have correlations larger than
> +/-0.6:
> synth=data.frame(x=rnorm(10,1),y=rnorm(10,2),z=rnorm(10,0.5))
> w=cor(synth,use="pairwise.complete.obs")
> w[,sapply(w,abs(w),">",0.6)]
> The problem is that using sapply with ">" or "<" doesn´t seem to work.
> How could I solve this problem?

If you want to extract correlations with absolute value >0.6, then simply use w[abs(w)>0.6]

Please, reread the help("sapply"). You give some extra arguments to this function.
The first goes the vector, the second goes the function, and then - additional arguments to the function.
Probably, you wanted w[sapply(abs(w),">",0.6)] This gives the same result.

View this message in context:
Sent from the R help mailing list archive at

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 11 Jun 2007 - 12:43:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 11 Jun 2007 - 13:31:49 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.