Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

Unpredictable results using cut() function in R to convert dates to 15 minute intervals

$
0
0

OK, this is making me crazy.

I have several datasets with time values that need to be rolled up into 15 minute intervals.

I found a solution here that works beautifully on one dataset. But on the next one I try to do I'm getting weird results. I have a column with character data representing dates:

                 BeginTime
-------------------------------
    1           1/3/19 1:50 PM
    2           1/3/19 1:30 PM
    3           1/3/19 4:56 PM
    4          1/4/19 11:23 AM
    5           1/6/19 7:45 PM
    6          1/7/19 10:15 PM
    7          1/8/19 12:02 PM
    8          1/9/19 10:43 PM

And I'm using the following code (which is exactly what I used on the other dataset except for the names)

df$by15 = cut(mdy_hm(df$BeginTime), breaks="15 min")

but what I get is:

                    BeginTime              by15
-------------------------------------------------------
    1           1/3/19 1:50 PM      2019-01-03 13:36:00
    2           1/3/19 1:30 PM      2019-01-03 13:21:00
    3           1/3/19 4:56 PM      2019-01-03 16:51:00
    4          1/4/19 11:23 AM      2019-01-04 11:21:00
    5           1/6/19 7:45 PM      2019-01-06 19:36:00
    6          1/7/19 10:15 PM      2019-01-07 22:06:00
    7          1/8/19 12:02 PM      2019-01-08 11:51:00
    8          1/9/19 10:43 PM      2019-01-09 22:36:00
    9         1/10/19 11:25 AM      2019-01-10 11:21:00

Any suggestions on why I'm getting such random times instead of the 15-minute intervals I'm looking for? Like I said, this worked fine on the other data set.


Viewing all articles
Browse latest Browse all 201945

Trending Articles