I would like to determine if a vector always increases or always decreases in R.
Ideally, if I had these three vectors:
asc=c(1,2,3,4,5) des=c(5,4,3,2,1) non=c(1,3,5,4,2)
I hope the first two will return TRUE, and the last will return FALSE.
I tried several approaches. First I tried:
> is.ordered(asc) [1] FALSE > is.ordered(des) [1] FALSE > is.ordered(non) [1] FALSE
And I also tried:
> order(non) [1] 1 5 2 4 3
And I hoped that I could just compare this vector with 1,2,3,4,5 and 5,4,3,2,1 , but even this returns a line of logic, and not a single truth or falsehood:
> order(non)==c(1,2,3,4,5) [1] TRUE FALSE FALSE TRUE FALSE
sorting r order
user3603093
source share