
Dear Simon & R-Users.I have applied your solution also for larger buffer window,and it's working well.
But I'm getting the problem harder.I have two vectors: x<- c(0,0,0,0,1,0,0,0,0,1,0,0,0) y<- c(0,-10,0,-10,0,0,0,0,-10,0,0,0,0)
And I want to know where the value -1 in x have at least 2 values -10 in y.Considering a buffer of three position before x.
i.e. in this example only the figure 1 in position x[5] satisfies the criteria,because y has the values -10 in position y[2] and y[4].
I tried in this way, but I don't know how to say"at least 2 on three conditions on y must be true":
which(x==1 & (        c(0,y[1:12])==-10 |        c(0,0, y[1:11])==-10|        c(0,0,0, y[1:10])==-10    ))
thank in advance for you help,
Francesco
> Date: Wed, 17 Oct 2012 10:36:46 +1100
> Subject: Re: [R] vectors comparison
> From: sleepingwell@gmail.com
> To: nutini.francesco@gmail.com
> CC: r-help@r-project.org
> 
> Your question does not seem to make sense - there is no value of -500
> in Y (did you mean -10?). Anyway, I think this might work:
> 
> which(y==-10 & (x==1 | c(0, x[-length(x)]) == 1 | c(x[-1], 0) == 1))
> 
> ... though one would think there is a more elegant way
> 
> 
> On Wed, Oct 17, 2012 at 10:07 AM, Francesco Nutini
> <nutini.francesco@gmail.com> wrote:
> >
> > Dear R-Users,
> > I'd like to have your help on this problem:
> > I have two vectors:x<- c(0,1,0,0,0,0,0,0,0,0,0,1,0)y<- c(0,0,-10,0,0,-10,0,-10,0,0,0,0,0)
> > And I want to know where the value -500 in y have a correspondence value 1 in x.Considering a buffer of one position before and after in x.i.e. in this example only the -10 in position y[3] satisfies the criteria, because x has in position x[2]the figure 1.
> > Thank in advance for you help,Francesco
> >
> >
> >
> >
> >
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
 		 	   		  
	[[alternative HTML version deleted]]


