From: Christos Hatzis <christos_at_nuverabio.com>

Date: Tue 09 Jan 2007 - 22:24:12 GMT

R-help@stat.math.ethz.ch 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. Received on Wed Jan 10 15:45:34 2007

Date: Tue 09 Jan 2007 - 22:24:12 GMT

That's true. Just need to negate the difference. Actually, straight diff can be used after reversing the vector:

apply(mat, 1, function(x) diff(sort(x, decreasing = TRUE)[2:1]))

I only have 3 columns in my matrix so sorting should not add much overhead, but I will time both versions.

Thanks again.

-Christos

Note that my first example can actually be simplified to:

apply(mat, 1, function(x) -diff(sort(x, decreasing = TRUE)[1:2]))

Since we really just need to negate the difference, rather than take the abs().

Using the second example more generally, you would have to use something like:

apply(mat, 1, function(x) diff(sort(x)[-c(1:(length(x) - 2))]))

On Tue, 2007-01-09 at 16:39 -0500, Christos Hatzis wrote:

> Thanks, Marc.

*> This is what I was trying to do but could not get it to work.
**>
**> -Christos
*

<snip>

R-help@stat.math.ethz.ch 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. Received on Wed Jan 10 15:45:34 2007

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.1.8, at Wed 10 Jan 2007 - 08:30:25 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*