[R] Feed rle() output to hist()
Newbie1234
larry at riskengineer.com
Tue Mar 26 22:02:33 CET 2013
I want to make a histogram from the lengths vector which is part of the
output of rle. But I don't know how to access that vector so that I use it
as an argument of hist(). What argument must I use so that I use the
lengths vector as an input to hist()?
Example output is:
Run Length Encoding
lengths: int [1:4] 1 2 3 3
values : num [1:4] -1 1 -1 1
A printout of the function rle() may give some clues, however - not enough
for me. Here is the print out of rle()
> rle
function (x)
{
if (!is.vector(x) && !is.list(x))
stop("'x' must be an atomic vector")
n <- length(x)
if (n == 0L)
return(structure(list(lengths = integer(), values = x),
class = "rle"))
y <- x[-1L] != x[-n]
i <- c(which(y | is.na(y)), n)
structure(list(lengths = diff(c(0L, i)), values = x[i]),
class = "rle")
}
<bytecode: 0x7fc7060a52d8>
<environment: namespace:base>
--
View this message in context: http://r.789695.n4.nabble.com/Feed-rle-output-to-hist-tp4662554.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list