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 <pifferdav...@gmail.com> 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 indexing in a for loop such as (bad, > incorrect example): > for (i in v){ > if [i]==[i-2] print T > else print F > } > > However, this is obviously wrong. > Can someone provide a nice way to solve this? > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.