Displaying 4 results from an estimated 4 matches for "oldmeadow".
2008 Dec 16
8
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
2008 Aug 26
4
sequence with start and stop positions
Hi,
I have a vector of start positions, and another vector of stop positions,
eg start<-c(1,20,50)
stop<-c(7,25,53)
Is there a quick way to create a sequence from these vectors?
new<-c(1,2,3,4,5,6,7,20,21,22,23,24,25,50,51,52,53)
the way Im doing it at the moment is
pos<-seq(start[1],stop[1])
for (i in 2:length(start)){
new<-seq(start[i],stop[i])
pos<-c(pos,new)
}
2008 Aug 28
2
sample consecutive integers efficiently
Hi all,
I have some rough code to sample consecutive integers with length
according to a vector of lengths
#sample space (representing positions)
pos<-c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)
#sample lengths
lengths<-c(2,3,2)
From these two vectors I need a vector of sampled positions.
the sampling is without replacement, making things tough as the sampled
integers need
2008 Dec 16
1
simulate binary markov chain
Hi all, I was hoping somebody may know of a function for simulating a
large binary sequence (length >10 million) using a (1st order) markov
model with known (2x2) transition matrix. It needs to be reasonably
fast. I have tried the following;
mc<-function(sq,P){
s<-c()
x<-row.names(P)
n<-length(sq)
p1<-sum(sq)/n
s[1] <- rbinom(1,1,p1);
for ( i in 2:n){
s[i]