another way of thinking is to turn the sequences into strings
if your data is db
>apply(db,1,function(x) length(gregexpr('892',paste(c(x),collapse=''))[[1]]))
[1] 1 3 1 1 3 2
Weidong Gu
On Sat, Jul 2, 2011 at 3:40 PM, Trying To learn again
wrote:
> Hi all,
>
> I have a data matrix likein "i
On Sat, Jul 2, 2011 at 3:40 PM, Trying To learn again
wrote:
> Hi all,
>
> I have a data matrix likein "input.txt"
>
> 8 9 2 5 4 5 8 5 6 6
> 8 9 2 8 9 2 8 9 2 1
> 8 9 2 5 4 5 8 5 6 4
> 8 9 2 5 4 5 8 5 6 6
> 8 9 2 8 9 2 8 9 2 1
> 8 9 2 5 4 5 8 9 2 2
>
>
> In this example will be an 6x10 matrix
I suppose the easiest way to make this is to use loops and construct a zero
matrix to be completed each time the sequence accompleixes, don´t you?
I will try this evening¡¡¡
2011/7/2 Trying To learn again
> Hi all,
>
> I have a data matrix likein "input.txt"
>
> 8 9 2 5 4 5 8 5 6 6
> 8 9 2 8
Sorry, I forgot to attach the original post, so here once more with a cosmetic
change:
x <- as.matrix( read.table( "matr.txt") )
bingo <- 0
for( i in 1:dim( x )[1] )
{
for( j in 1:dim( x )[2] - 2 )
{
if( x[i,j] == 8 && x[i,j+1] == 9 && x[i,j+2] == 2 )
{
bingo <- bingo + 1
On Saturday 02 July 2011 21:40:24 Trying To learn again wrote:
Clumsy but it works (replace the bingo stuff with what you want to do next):
x <- as.matrix( read.table( "input.txt") )
xdim <- dim( x )
ix <- xdim[ 1 ]
jx <- xdim[ 2 ] - 2
bingo <- 0
for( i in 1:ix )
{
for( j in 1:jx )
{
if
Hi all,
I have a data matrix likein "input.txt"
8 9 2 5 4 5 8 5 6 6
8 9 2 8 9 2 8 9 2 1
8 9 2 5 4 5 8 5 6 4
8 9 2 5 4 5 8 5 6 6
8 9 2 8 9 2 8 9 2 1
8 9 2 5 4 5 8 9 2 2
In this example will be an 6x10 matrix (or data frame)
I want to detect how many times in a row appears this combination
6 matches
Mail list logo