Skip to content
Prev 308119 / 398503 Next

cannot coerce class '"rle"' into a data.frame

On Oct 16, 2012, at 12:54 PM, Sam Steingold <sds at gnu.org> wrote:

            
It is telling you that there is not an as.data.frame() method for objects of class 'rle':

x <- rev(rep(6:10, 1:5))

RES <- rle(x)
List of 2
 $ lengths: int [1:5] 5 4 3 2 1
 $ values : int [1:5] 10 9 8 7 6
 - attr(*, "class")= chr "rle"


Since 'RES' is a list with a class attribute, you can unclass() it and then coerce to a data.frame:
lengths values
1       5     10
2       4      9
3       3      8
4       2      7
5       1      6
'data.frame':	5 obs. of  2 variables:
 $ lengths: int  5 4 3 2 1
 $ values : int  10 9 8 7 6


Regards,

Marc Schwartz