Skip to content
Prev 320360 / 398506 Next

Feed rle() output to hist()

Do you want a histogram of the length distribution, or a barplot of
the actual lengths?

Either way,

myrle$lengths

will get it, if myrle is the output of rle().

?rle

tells you that:
     ?rle()? returns an object of class ?"rle"? which is a list with
     components:

 lengths: an integer vector containing the length of each run.

  values: a vector of the same length as ?lengths? with the
          corresponding values.


If you don't understand what list components are, you should certainly
read Introduction to R. Looking at the help is always a better place
to start than looking at the code, though the last line of the code
shows exactly the same thing.

Here's an example:

x <- c(rev(rep(6:10, 1:5)), 5, rep(6:10, 1:5))
myrle <- rle(x)

hist(myrle$lengths)
barplot(myrle$lengths)


Sarah
On Tue, Mar 26, 2013 at 5:02 PM, Newbie1234 <larry at riskengineer.com> wrote:
--
Sarah Goslee
http://www.functionaldiversity.org