Thanks, That's great!
Could you please give me some advice if I have more than one replicate for each number in A? for example: [B is my expect output]
DT<- data.table(A=c(1,1,1,1,2,3,4,4,5,6,7,8,8,9,1,2,3,4,5,5,5,6,6,6,7,7,7,8,9,1,2,2,2,3))
The number of each value might be different.
The expected output [B] is:
A 1,1,1,1,2,3,4,4,5,6,7,8,8,9,1,2,3,4,5,5,5,6,6,6,7,7,7,8,9,1,2,2,2,3
B 1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3
Thanks again,
Milad