Re: [R] detect subset in series

2011-11-16 Thread threshold
Thanks for the answer. I found that smth like below works subset <- c(1,0,0) series <- c(1,1,1,0,1,0,0,1,1,0,0,0,0,1) subset1 <- paste(subset, collapse='') series1 <- paste(series, collapse='') xx <- gregexpr(subset1, series1, fixed=TRUE) as.numeric(xx[[1]]) ## yields the first element numbers i

Re: [R] detect subset in series

2011-11-16 Thread R. Michael Weylandt
If your data is also binary like that below, it might be useful/easier to use regular expressions tools as well: e.g., series <- c(1,1,1,0,1,0,0,1,1,0,0,0,0,1) subset <- c(0,0,0,0) print(regexpr(paste(subset, collapse = ""),paste(series, collapse = ""))) Michael On Wed, Nov 16, 2011 at 9:55 AM,

Re: [R] detect subset in series

2011-11-16 Thread David Winsemius
On Nov 16, 2011, at 8:25 AM, threshold wrote: Dear R Users, I am curious whether there is any simple solution o my problem. My example 'series': series <- c(1,1,1,0,1,0,0,1,1,0,0,0,0,1) My 'subset' of interest: subset <- c(0,0,0,0) Is there any function which tells me that the subset exist

[R] detect subset in series

2011-11-16 Thread threshold
Dear R Users, I am curious whether there is any simple solution o my problem. My example 'series': series <- c(1,1,1,0,1,0,0,1,1,0,0,0,0,1) My 'subset' of interest: subset <- c(0,0,0,0) Is there any function which tells me that the subset exists in my series, and gives me position where in serie