[R] vectors comparison

Simon Knapp sleepingwell at gmail.com
Wed Oct 17 01:36:46 CEST 2012


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 at 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 at 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.




More information about the R-help mailing list