s-news
[Top] [All Lists]

Summary: Length of a run of contiguous values above a threshold

To: S-News <s-news@wubios.wustl.edu>
Subject: Summary: Length of a run of contiguous values above a threshold
From: Kim Elmore <elmore@nssl.noaa.gov>
Date: Thu, 26 Jul 2001 09:47:24 -0500
In-reply-to: <OF4EA70F13.A460BC7F-ON85256A95.00509C50@cbis.com>
As usual, inside of a few minutes, I'm shown the answer to my question. Thanks goes to James Holtman. As I expected, there *is* an S-Plus native function that will allow me to do what I need. Thanks again, James!

It turns out that I had skipped over the answer: when I entered "run" in S-Plus's windows help utility, I skipped over Run Length Encoding, assuming that it was not what I wanted. Shame on me. Here is his answer along with my original question. With this, I can easily write a function that does what I need. Thank you all for a marvelous repository of knowledge.

Kim Elmore

At 10:41 AM 7/26/2001 -0400, you wrote:

'rle' will give you the run lengths of data in your vector.  Here is an
example:

> x.1 <- c(1,1,1,1,1,1,3,3,3,3,3,3,3,6,6,6,6,6,6,6,6,8,8,8,8,8,8,8,8)
> rle(x.1)
$lengths:
[1] 6 7 8 8

$values:
[1] 1 3 6 8

By looking at the '$values' that are above your threshold, you can reference the "$lengths" for how long they are.

Hope this helps.






Kim Elmore <elmore@nssl.noaa.gov>@lists.biostat.wustl.edu on 07/26/2001
10:15:37

Sent by:  s-news-owner@lists.biostat.wustl.edu


To:   S-News <s-news@wubios.wustl.edu>
cc:
Subject:  [S] Length of a run of contiguous values above a threshold


I'm faced with a simple task that I'm almost sure I've done (or seen done)
before, but that I can't recall.  Within a vector, I want to identify the
length of contiguous runs of numeric data that are above a certain
(arbitrary) threshold.  I was sure that a native S-Plus function exists
that does this, but I can't find it if there is one.

I can kludge/hack my own if need be (S Programming is a marvelous book, but
it's hard to get past some of my old F77 habits), but if there's something
already there that I've overlooked, I'd prefer to use it.

Thanks to everyone for such a marvelous list!

Kim Elmore
                           Kim Elmore, Ph.D.
"All of weather is divided into three parts: Yes, No, and Maybe. The
greatest of these is Maybe" The original Latin appears to be garbled.

---------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news



--

NOTICE:  The information contained in this electronic mail transmission is
intended by Convergys Corporation for the use of the named individual or
entity to which it is directed and may contain information that is
privileged or otherwise confidential.  If you have received this electronic
mail transmission in error, please delete it from your system without
copying or forwarding it, and notify the sender of the error by reply email
or by telephone (collect), so that the sender's address records can be
corrected.

                          Kim Elmore, Ph.D.
"All of weather is divided into three parts: Yes, No, and Maybe. The
greatest of these is Maybe" The original Latin appears to be garbled.


<Prev in Thread] Current Thread [Next in Thread>
  • Summary: Length of a run of contiguous values above a threshold, Kim Elmore <=