Generate timestamp for each ID in R in ascending order : <p>I tried to generate timestamp in R for my data and I'm having problem to create them in order where each ID will take group of timestamp for the period of 14 days and I need to create them in ascending order.</p>

<p>My data looks like :</p>

<pre><code>ID      Lat          Long    Traffic   Time
1      -80.424      40.4242    54       1am
2      -80.114      40.4131    30       1am
3      -80.784      40.1142    12       1am
1      -80.424      40.4242    22       2am
2      -80.114      40.4131    31       2am
3      -80.784      40.1142    53       2am
</code></pre>

<p>And I want my data to be like this :</p>

<pre><code>ID      Lat          Long    Traffic        Time_New
1      -80.424      40.4242    54       2018/01/01 01:00
2      -80.114      40.4131    30       2018/01/01 01:00
3      -80.784      40.1142    12       2018/01/01 01:00
1      -80.424      40.4242    22       2018/01/02 02:00
2      -80.114      40.4131    31       2018/01/02 02:00
3      -80.784      40.1142    53       2018/01/02 02:00
</code></pre>

<p>I used the code below to 24 hrs for each ID for the period time of 2 weeks
but I got this output but the order of the timestamp is not what I want plus it added the value of traffic from the previous values and I want to generate the new values of the new timestamp based on the average of the traffic flow of each ID.</p>

<pre><code>library(data.table)
Data&lt;- setDT(Data)[, .SD[rep(1:.N, ID)]][,Time_New:= seq(as.POSIXct("2018-01-01 01:00"), as.POSIXct("2018-01-14 00:00"),by = "hour"),by = .(Lat, Long)][]




ID      Lat          Long    Traffic        Time_New           Time
1      -80.424      40.4242    54       2018/01/01 01:00        1am
2      -80.114      40.4131    30       2018/01/01 01:00        1am
3      -80.784      40.1142    12       2018/01/01 01:00        1am
1      -80.424      40.4242    54       2018/01/02 02:00        2am
2      -80.114      40.4131    54       2018/01/02 03:00        2am 
1      -80.424      40.4242    54       2018/01/01 02:00        2am
2      -80.114      40.4131    54       2018/01/01 03:00        2qm
3      -80.784      40.1142    30       2018/01/01 01:00        3am
3      -80.784      40.1142    30       2018/01/01 02:00        3am
3      -80.784      40.1142    30       2018/01/01 03:00        3am
</code></pre>

<p>As you see It listed  the first 3 IDs in the order I want then, it starts repeating ID 1, 2 and for ID 3 it put list of time from 1-3, and copy same traffic value.</p>

<p>Anyone has idea how to do generate the timestamp for each Id group in ascending order?</p>

<p>it will be much appreciated. </p>
