24 hour time count observations.

I have a large data set that represents observations at a given time in 24 hour format. I would like to get a histogram of just how many observations happened at each time listed. The data is in this format (Just a snippet):

Is this possible?


Hi @jchimento,
Yes, it is possible.
I assume you don't want to see observations per each timestamp to the second, correct? I understand that you'd like to aggregate to an hour level or something, is that right?

You could assign your time column an hms class (using lubridate package) and then extract an hour from it by using an hour() function (same package).

x <- "23:15:02"
[1] "23:15:02"
x <- hms(x)
[1] "23H 15M 2S"
x_hour <- hour(x)
[1] 23

Or you can just plot your values right away after class assignment without extracting the hour, but your results may be tad granular.

I'm sure there is a base R solution with Posi-something class, but I have no expertise in that domain.

Thank you! That seems to work.


1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.