Dear Erik,
Thanks for the mapply idea. I never got around to understand all those apply
functions.
I am still curious as to why the other loop didnt work. I even tried the
debug but doesnt help.
Anyway I will leave that for now.
Thanks a lot for your help.
Regards,
Roy


On Mon, Jan 24, 2011 at 11:43 PM, Erik Iverson <eriki@ccbr.umn.edu> wrote:

>
>
> 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"
>



-- 
Best Regards,
Roy

	[[alternative HTML version deleted]]

