Displaying 2 results from an estimated 2 matches for "issameasprevious".
2017 Jul 23
0
matching element of a vector to i-2nd element
...=[i-2] print T
> else print F
> }
>
> However, this is obviously wrong.
Why don't you provide code that is actually valid R code so we
can run it. Then we can see if it does the right thing or not.
> Can someone provide a nice way to solve this?
Does this do what you want?
isSameAsPrevious <- function(v, k=1) c(rep(FALSE, k), head(v,n=-k) ==
tail(v, n=-k))
Then:
> isSameAsPrevious(v, 2)
[1] FALSE FALSE FALSE TRUE
H.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://urldefense.p...
2017 Jul 23
4
matching element of a vector to i-2nd element
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