Re: [R] matching element of a vector to i-2nd element

2017-07-23 Thread Davide Piffer
Thanks a lot, Herve'. This worked! On 23 July 2017 at 22:19, Hervé Pagès wrote: > Hi, > > On 07/23/2017 11:43 AM, Davide Piffer wrote: >> >> I have a df with a vector v. For each element of the vector, I want to >> know whether the i-2nd element is the same as the ith element. For >> example: >>

Re: [R] matching element of a vector to i-2nd element

2017-07-23 Thread Jeff Newmiller
You can compare the elements that make sense to compare, and fill in the ones that don't make sense to compare yourself using the c function. Hint: no looping or if function are necessary. v[ seq( 2, length( v ) ] == v[ seq.int( length( v ) - 2 ) ] -- Sent from my phone. Please excuse my bre

Re: [R] matching element of a vector to i-2nd element

2017-07-23 Thread Hervé Pagès
Hi, On 07/23/2017 11:43 AM, Davide Piffer wrote: I have a df with a vector v. For each element of the vector, I want to know whether the i-2nd element is the same as the ith element. For example: given v=c(A,C,D,C) the result should be: FALSE,FALSE,FALSE,TRUE. I attempted something using indexi

Re: [R] matching element of a vector to i-2nd element

2017-07-23 Thread Davide Piffer
No homework. Just a genuine question On 23 July 2017 at 22:00, Bert Gunter wrote: > Homework?? There is a no homework policy on this list. > > Cheers, > Bert > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Ber

Re: [R] matching element of a vector to i-2nd element

2017-07-23 Thread Bert Gunter
Homework?? There is a no homework policy on this list. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sun, Jul 23, 2017 at 11:43 AM, Davide Piffer