why?> rleRun Length Encoding lengths: int [1:1650061] 2 2 8 2 4 5 6 3 26 46 ... values : chr [1:1650061] "4bbf9e94cbceb70c BG bg" "4fbbf2c67e0fb867 SK sk" ...> as.data.frame(rle)Error in as.data.frame.default(vertices.rle) : cannot coerce class '"rle"' into a data.frame it seems that rle.df <- data.frame(values=rle$values,length=rle$length) works and DTRT. -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://iris.org.il http://memri.org http://www.PetitionOnline.com/tap12009/ http://camera.org char*a="char*a=%c%s%c;main(){printf(a,34,a,34);}";main(){printf(a,34,a,34);}
Hi, vec1<-c(1,2,3,4,4,5,6) ?str(rle(vec1)) #List of 2 # $ lengths: int [1:6] 1 1 1 2 1 1 # $ values : num [1:6] 1 2 3 4 5 6 ?#- attr(*, "class")= chr "rle" do.call(data.frame,rle(vec1)) ?# lengths values #1?????? 1????? 1 #2?????? 1????? 2 #3?????? 1????? 3 #4?????? 2????? 4 #5?????? 1????? 5 #6?????? 1????? 6 A.K. ----- Original Message ----- From: Sam Steingold <sds at gnu.org> To: r-help at r-project.org Cc: Sent: Tuesday, October 16, 2012 1:54 PM Subject: [R] cannot coerce class '"rle"' into a data.frame why?> rleRun Length Encoding ? lengths: int [1:1650061] 2 2 8 2 4 5 6 3 26 46 ... ? values : chr [1:1650061] "4bbf9e94cbceb70c BG bg" "4fbbf2c67e0fb867 SK sk" ...> as.data.frame(rle)Error in as.data.frame.default(vertices.rle) : ? cannot coerce class '"rle"' into a data.frame it seems that rle.df <- data.frame(values=rle$values,length=rle$length) works and DTRT. -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://iris.org.il http://memri.org http://www.PetitionOnline.com/tap12009/ http://camera.org char*a="char*a=%c%s%c;main(){printf(a,34,a,34);}";main(){printf(a,34,a,34);} ______________________________________________ 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.
On Oct 16, 2012, at 12:54 PM, Sam Steingold <sds at gnu.org> wrote:> why? > >> rle > Run Length Encoding > lengths: int [1:1650061] 2 2 8 2 4 5 6 3 26 46 ... > values : chr [1:1650061] "4bbf9e94cbceb70c BG bg" "4fbbf2c67e0fb867 SK sk" ... >> as.data.frame(rle) > Error in as.data.frame.default(vertices.rle) : > cannot coerce class '"rle"' into a data.frame > > it seems that > > rle.df <- data.frame(values=rle$values,length=rle$length) > > works and DTRT.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)> str(RES)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:> as.data.frame(unclass(RES))lengths values 1 5 10 2 4 9 3 3 8 4 2 7 5 1 6> str(as.data.frame(unclass(RES)))'data.frame': 5 obs. of 2 variables: $ lengths: int 5 4 3 2 1 $ values : int 10 9 8 7 6 Regards, Marc Schwartz