Yes, unfortunately rle doesn't recode NAs (it would be easier if it does). The problem is that I can't consider any value as out of range (not 999, not 99999 and so on...) and use it in place of NAs.
–
digEmAllSep 28 '12 at 16:02

@Sven not sure if your comment is for my solution or the rle and NA thing. My solution works with consecutive integers as the example I provide shows. But alas it won't work for didEmAll's needs. I mean you could convert this to character by adding a character value and then replace and convert back but it was already a less cool solution to begin with :)
–
Tyler RinkerSep 28 '12 at 16:54

2

Don't forget about inverse.rle. It essentially just does what you have in the last line of code but is a little bit safer.
–
DasonSep 28 '12 at 19:16

@Dason Forget? I never knew about it. I added it to show its use.
–
Tyler RinkerSep 28 '12 at 19:25