[R-sig-Geo] Search in number sequence

Robert Hijmans r.hijmans at gmail.com
Tue Jul 12 08:57:28 CEST 2011


> I have a vector with repeated values like 
> ...
> I want to search the sequence in this vector. And search should give me
> the 
> index of matching sequence. 

If there is not a more direct way to do this, you can perhaps use the
movingFun function in raster for this.

library(raster)
values <- c(1:10, 1:10, 1:10)
pattern <- 5:7
fun <- function(x, ...) all(x == pattern)

which( movingFun(values, length(pattern), fun, type='from') )
# [1]  5 15 25
pattern <- c(9:10,1:2)
which( movingFun(values, length(pattern), fun, type='from') )
# [1]  9 19

Robert


--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Search-in-number-sequence-tp6572599p6573987.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list