[R] How to index the occasions in a vector repeatedly under condition 1? if not, it will give a new index.

Lijun Zhao ||junzh@o0606 @end|ng |rom gm@||@com
Wed Feb 19 07:56:06 CET 2020


Dear All,

could you please help me how to get the output from the following example?


x<-c(543,  543,  543,  543,  551 , 551 ,1128 ,1197, 1197)

diff<-x-lag(x)

diff

[1]  NA   0   0   0   8   0 577  69   0

how to index the occassions in x repeatedly if the diff>15? if not, it will
give a new index

i want the output be like y

y<-c(1,1,1,1,1,1,2,3,3)


thanks,


Lijun

	[[alternative HTML version deleted]]



More information about the R-help mailing list