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
Not the most efficient way would be to use a loop.... If x is your rel object, you can do the following: for (i in 1:length(x$values)) { cat("(",x$values[i],",",x$lengths[i],") ") if (i %% 10 == 0) cat("\n") } cat("\n") --- 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. >
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. >