Say I have two vectors:
a<-c(6,6,NA,NA,9,9,8,NA,NA,7,NA,NA,NA,NA)
b<-c(NA,NA,NA,NA,NA,NA,NA,NA,NA,8,NA,5,7,NA)
If there is any increase in the vector, I change the values to NA.
Say, in vector a
, fifth value is 9
, increase from last value 6
so it will be NA
and all the values afterwards. And for b
vector, there is a change from 5
to 7
, so 7
onward it must be NA
.
Expected output:
a = c(6,6,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA)
b = c(NA,NA,NA,NA,NA,NA,NA,NA,NA,8,NA,5,NA,NA)
If there is no increase in the vector, the vector remains the same.
How to create a function to achieve this?