[R] crazy loop error.
Erik Iverson
eriki at ccbr.umn.edu
Mon Jan 24 23:43:32 CET 2011
Roy Mathew wrote:
> Thanks for the reply Erik, As you mentioned, grouping consecutive
> elements of 'a' was my idea.
> I am unaware of any R'ish way to do it. It would be nice if someone in
> the community knows this.
Is this the idea you're trying to execute? It uses ?rle and ?mapply.
a <- c(2,3,5,5,5,6,6,7)
mapply(rep, "hello", rle(a)$lengths, USE.NAMES = FALSE)
[[1]]
[1] "hello"
[[2]]
[1] "hello"
[[3]]
[1] "hello" "hello" "hello"
[[4]]
[1] "hello" "hello"
[[5]]
[1] "hello"
More information about the R-help
mailing list