Skip to content
Back to formatted view

Raw Message

Message-ID: <49472C6B.5000704@student.qut.edu.au>
Date: 2008-12-16T04:19:55Z
From: Chris Oldmeadow
Subject: sliding window over a large vector

Hi all,

I have a very large binary vector, I wish to calculate the number of 
1's  over sliding windows.

this is my very slow function

slide<-function(seq,window){
   n<-length(seq)-window
   tot<-c()
   tot[1]<-sum(seq[1:window])   
   for (i in 2:n) {
      tot[i]<- tot[i-1]-seq[i-1]+seq[i]
   }
   return(tot)
}
 
this works well for for reasonably sized vectors. Does anybody know a 
way for large vectors ( length=12 million), im trying to avoid using C.

Thanks,
Chris