Re: [R] counting strings of identical values in a matrix

2007-11-19 Thread Marc Schwartz
Moshe, Gabor posted that same solution shortly after my reply on Thursday. I had one of those "head banging" episodes shortly thereafter... :-) Regards, Marc On Mon, 2007-11-19 at 17:46 -0800, Moshe Olshansky wrote: > How about adding an artificial last row containing no > 1's (say a row of z

Re: [R] counting strings of identical values in a matrix

2007-11-19 Thread Moshe Olshansky
How about adding an artificial last row containing no 1's (say a row of zeros)? --- Marc Schwartz <[EMAIL PROTECTED]> wrote: > > On Thu, 2007-11-15 at 17:53 +0100, A M Lavezzi > wrote: > > thank you. > > I did not think about the case of overlapping of > > 1's from the end of one column to the

Re: [R] counting strings of identical values in a matrix

2007-11-16 Thread A M Lavezzi
Marc and Gabor thank you so much. Also for making me realize how litte I know about R's potential best, Mario ps I actually thought about appending that row of zeros while waking up this morning.. At 18.35 15/11/2007, Gabor Grothendieck wrote: >We can append a row of 0's to handle that case:

Re: [R] counting strings of identical values in a matrix

2007-11-15 Thread Gabor Grothendieck
We can append a row of 0's to handle that case: with(rle(as.vector(rbind(prova, 0))), table(lengths[values == 1])) On Nov 15, 2007 11:36 AM, Marc Schwartz <[EMAIL PROTECTED]> wrote: > Ah...OK. I misunderstood then. I thought that you wanted the number of > runs of 1's in each column. > > This i

Re: [R] counting strings of identical values in a matrix

2007-11-15 Thread Marc Schwartz
Ah...OK. I misunderstood then. I thought that you wanted the number of runs of 1's in each column. This is actually easier, _if_ there is not an overlap of 1's from the end of one column to the start of the next column: res <- rle(as.vector(prova)) > res Run Length Encoding lengths: int [1:11]

Re: [R] counting strings of identical values in a matrix

2007-11-15 Thread Marc Schwartz
On Thu, 2007-11-15 at 17:53 +0100, A M Lavezzi wrote: > thank you. > I did not think about the case of overlapping of > 1's from the end of one column to the start of the next, > this would actually be a problem > > In the simulations I am running each column > corresponds to the path followed

Re: [R] counting strings of identical values in a matrix

2007-11-15 Thread Marc Schwartz
Thanks Gabor. Nice solution. Marc On Thu, 2007-11-15 at 12:35 -0500, Gabor Grothendieck wrote: > We can append a row of 0's to handle that case: > > with(rle(as.vector(rbind(prova, 0))), table(lengths[values == 1])) > > > > On Nov 15, 2007 11:36 AM, Marc Schwartz <[EMAIL PROTECTED]> wrote: >

Re: [R] counting strings of identical values in a matrix

2007-11-15 Thread A M Lavezzi
thank you. I did not think about the case of overlapping of 1's from the end of one column to the start of the next, this would actually be a problem In the simulations I am running each column corresponds to the path followed by an agent across states of a stochastic process, so I would like t

Re: [R] counting strings of identical values in a matrix

2007-11-15 Thread A M Lavezzi
Dear Marc thank you so much! One thing: writing xx=[1,2,1,1] is not a typo: I read it as the count of runs of different length starting from 1. In "prova" I have 1 run of length one, 2 runs of length two, 1 run of length three and 1 run of length four. Can I abuse of your time and ask how to

Re: [R] counting strings of identical values in a matrix

2007-11-15 Thread Marc Schwartz
On Thu, 2007-11-15 at 15:51 +0100, A M Lavezzi wrote: > Hello > > I have this problem. I have a large matrix of this sort: > > > prova > [,1] [,2] [,3] [,4] > [1,]3333 > [2,]3331 > [3,]1333 > [4,]1113 > [5,]311

[R] counting strings of identical values in a matrix

2007-11-15 Thread A M Lavezzi
Hello I have this problem. I have a large matrix of this sort: > prova [,1] [,2] [,3] [,4] [1,]3333 [2,]3331 [3,]1333 [4,]1113 [5,]3113 [6,]3113 [7,]1313 [8,]1333