'how to combine all of the table into datetime format in R

So I have table called flights with column year, month, day, hour, and minutes.

I want to combine in to datetime format with this code.

as.POSIXct(paste(flights$year, flights$month, flights$day, flights$hour, flights$minute), format="%Y-%m-%d %H:%M:%S")

The table is like this

ID  year      month day            hour  minutes
1   2013       1    1               15     15

FYI, I followed this solution.

https://stackoverflow.com/a/47996249/17067132

based on @Rui Barradas suggestion, here's what i do with dput(head(flights))

structure(list(year = c(2013L, 2013L, 2013L, 2013L, 2013L, 2013L
), month = c(1L, 1L, 1L, 1L, 1L, 1L), day = c(1L, 1L, 1L, 1L, 
1L, 1L), dep_time = c(517L, 533L, 542L, 544L, 554L, 554L), sched_dep_time = c(515L, 
529L, 540L, 545L, 600L, 558L), dep_delay = c(2, 4, 2, -1, -6, 
-4), arr_time = c(830L, 850L, 923L, 1004L, 812L, 740L), sched_arr_time = c(819L, 
830L, 850L, 1022L, 837L, 728L), arr_delay = c(11, 20, 33, -18, 
-25, 12), carrier = c("UA", "UA", "AA", "B6", "DL", "UA"), flight = c(1545L, 
1714L, 1141L, 725L, 461L, 1696L), tailnum = c("N14228", "N24211", 
"N619AA", "N804JB", "N668DN", "N39463"), origin = c("EWR", "LGA", 
"JFK", "JFK", "LGA", "EWR"), dest = c("IAH", "IAH", "MIA", "BQN", 
"ATL", "ORD"), air_time = c(227, 227, 160, 183, 116, 150), distance = c(1400, 
1416, 1089, 1576, 762, 719), hour = c(5, 5, 5, 5, 6, 5), minute = c(15, 
29, 40, 45, 0, 58), time_hour = structure(c(1357034400, 1357034400, 
1357034400, 1357034400, 1357038000, 1357034400), tzone = "America/New_York", class = c("POSIXct", 
"POSIXt"))), row.names = c(NA, -6L), class = c("tbl_df", "tbl", 
"data.frame"))
r


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source