Hi Lauri,
A quick hack:
a <- lapply(g, 1, rle)
b <- sapply(a, function(x), x[[1]][x[[2]] == 1])
d <- cbind(rep(1:length(b), sapply(b, length)),
rep(sapply(b, length), sapply(b, length)),
unlist(b))
Best,
Jim
Lauri Nikkinen wrote:
> Hi R-users,
>
> I have a matrix si
2)))
I hope it helps.
Best,
Dimitris
- Original Message -
From: "Lauri Nikkinen" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, November 13, 2007 2:07 PM
Subject: [R] How to count the number of sequences in matrix?
> Hi R-users,
>
> I hav
Hi R-users,
I have a matrix similar to this. I would like to calculate the number
of 1 sequences in a row and also the length of the 1 sequence. For
instance, in the example below, row number one has four sequences of
number 1 (from left to right: 1; 1; 1,1; 1) and the corresponding
SeqCount is 4
3 matches
Mail list logo