runlength=function(x){

run=1

k=1

for( i in 2: length(x)){

if(x[i]==x[i-1]) run[k]=run[k]+1

else{

k=k+1

run=c(run,1)

}

}

return(run)

}

skip to main |
skip to sidebar
## Monday, July 23, 2007

###
Run Length

## About Me

A small function to get runlength from a vector

runlength=function(x){

run=1

k=1

for( i in 2: length(x)){

if(x[i]==x[i-1]) run[k]=run[k]+1

else{

k=k+1

run=c(run,1)

}

}

return(run)

}

runlength=function(x){

run=1

k=1

for( i in 2: length(x)){

if(x[i]==x[i-1]) run[k]=run[k]+1

else{

k=k+1

run=c(run,1)

}

}

return(run)

}

Subscribe to:
Posts (Atom)