Another (general moving window):
x <- c(1,3.0,3.1,3.2,1,1,2,3.0,3.1,3.2,4,4,5,6,5,3.0,3.1,3.2, 3.1,2,1,4,6,4.0,4,3.0,3.1,3.2,5,3.2,3.0,4) s <- c(3, 3.1, 3.2) sum(apply(embed(x, length(s)), 1, function(y) {all(y == rev(s))}))
See the embed output to see what happens.
As Arun apply indicates, here is pretty slow, and you can use embed along with the Arun matrix trick to achieve this much faster:
sum(colSums(matrix(embed(x, length(s)), byrow = TRUE, nrow = length(s)) == rev(s)) == length(s))