[R] printing levels as tuples

Gabor Grothendieck ggrothendieck at gmail.com
Fri Nov 23 02:21:02 CET 2007


Try this:

> x <- c("a", "a", "b", "b", "b") # test input
> with(rle(x), paste(values, lengths))
[1] "a 2" "b 3"


On Nov 22, 2007 7:32 PM, Alexy Khrabrov <deliverable at gmail.com> wrote:
> I'm running rle() on a long vector, and get a result which looks like
>
>  > uc
> Run Length Encoding
>   lengths: int [1:16753] 1 1 1 1 1 1 1 1 1 1 ...
>   values : int [1:16753] 29462748 22596107 18322820 14323315
> 12684505 9909036 7296916 6857692 5884755 5883697 ...
>
>
> I can print uc$names or uc$levels separately.  Is there any way to
> print them together as tuples, looking like
>
> (29462748, 1)   (22596107, 1) ...
> (5883697, 1) ...
> ...
>
> Cheers,
> Alexy
>
> ______________________________________________
> R-help at r-project.org 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.
>



More information about the R-help mailing list