What I presume is the desired answer can be arrived at via: diff(as.numeric(row.names(info)))
The command: m[,0] returns a matrix with zero columns, but it still has row names. Performing 'diff' on this returns another matrix with zero columns and one less row name. Patrick Burns [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and "A Guide for the Unwilling S User") Fred J. wrote: >dear R users > > I am having a problem with the output of diff for a numeric vector > which has the values (2,4,6,7), one expects to get 2 2 1 but I am > getting 4 6 7, here is the setup. > > > info <- with(rle(x), > data.frame(value = values, > start = cumsum(lengths)-lengths+1, > end = cumsum(lengths) > )[lengths > 1,] > ); > > x <- c(3,4,4,4,4,5,7,7,0,1,1,2,2,2); > > info > value start end > 2 4 2 5 > 4 7 7 8 > 6 1 10 11 > 7 2 12 14 > > #since I cann't get the first column of info, I cast > info into a matrix > > m <- as.matrix(info); > > diff(m[,0]) > > 4 > 6 > 7 > > any idea why this is happening? and how to get the > correct diff. > > > thank you > >--------------------------------- > > [[alternative HTML version deleted]] > >______________________________________________ >[email protected] mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > > > ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
