Skip to content
Prev 256200 / 398506 Next

Avoiding a loop

#Use the indexes of S in a sapply function.

N <- 10
S <- sample(c(0,1), size=N, replace=TRUE)
v1 <- sapply(c(1:N-1), function(i) S[i]&&S[i+1])

# Then
v2 <- (P > m)

# And I guess you can fill up the rest. Beware of the boundary
condition (the NA in v1)

Cheers,
jcb!
_______________________
http://twitter.com/jcborras
On Fri, Apr 8, 2011 at 5:30 AM, Worik R <worikr at gmail.com> wrote: