0

Following is an example of the column of the data frame

time
00:01:47
01:05:45
17:10:00

20,551,697 more rows

The data type is character

The data is from Citi Bikes New York for the period January 2019 to December 2019

Note: the data that starts with JC is for New Jersey not New York City

Since the data is very large you can download just one months data to try the code:

The column time is not a part of the original data frame and was created by me using the following code:

ridedata_clean$time <- format(as.POSIXct(ridedata_clean$starttime),format = "%H:%M:%S")

Then I tried to change the format from chr to time or date time, using the follwoing code:

ridedata_clean$time <- format(ridedata_clean$time, format ="%H:%M")

But glimpse() still shows the data type as so I used strptime(), but it still did'nt change the format

ridedata_clean$time <- strptime(ridedata_clean$time, "%H:%M:%S")

I have tried to use the round function, but it didn't work:

round(ridedata_clean$time, units = "hours")

The I tried lubridate, but it didn't work, the code below maybe wrong since I am typing from memory as I was unbale to save this change:

round_date(ridedata_clean$time, "%H,%M,%S")

I am new to data analysis and this is my second project, please help.

  • I think the answer that you need is in this post https://stackoverflow.com/questions/16803867/round-a-date-in-r-to-an-arbitrary-minute-hour-level-of-precision#:~:text=I%27m%20looking%20to%20group%20dates%20in%20R%20by,with%20e.g.%20a%20simple%20summarise%20ddply%20from%20plyr. – Isaac Aug 21 '22 at 19:38
  • @Isaac but column format is in will lubridate work ? – Madhav Ddas Aug 21 '22 at 19:41
  • @isaac I used the following code from your link ```ridedata_clean$time <- floor_date(now(), 'hour')``` it did round the to nearest hour but it also added todays data so now data is like this 2022-08-22 01:00:00, whereas required data is onlt time in HH:MM:SS – Madhav Ddas Aug 21 '22 at 19:45
  • @isaac it is rounding everything to 2022-08-22 01:00:00 – Madhav Ddas Aug 21 '22 at 20:03
  • R does not have a built-in time class. To handle times as times, they need to be part of a date time. To isolate the time component of a date time in the was you have tried, you need to save a character representation of a time, not the “time” itself. – Limey Aug 21 '22 at 21:04

0 Answers0