minute to hourly


I am trying to convert the time from minute to hourly, But I am getting some issues with that,
Could anyone please help me with this?

I am trying to convert the date format first, from char to POSIXct

data$new_date <- as.POSIXct(as.character(paste(data$date)), format="%Y-%m-%d %hh:%mm")

But getting a new_date as NA

The data can be found over here:



dat1$new_date  <- as.POSIXct(dat1$date, "%Y%m%d %hh%mm")

Note I renamed your data set to dat1

#> Loading required package: timechange
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>     date, intersect, setdiff, union
d <- read.csv("/Users/ro/projects/demo/data.csv")
# doubles all come over as NA, so drop
d <- d[,1]
# convert to date objects discarding seconds 
ymd_hm(d) |> head()
#> [1] "2022-01-16 00:00:00 UTC" "2022-01-16 00:01:00 UTC"
#> [3] "2022-01-16 00:02:00 UTC" "2022-01-16 00:03:00 UTC"
#> [5] "2022-01-16 00:04:00 UTC" "2022-01-16 00:05:00 UTC"

Created on 2023-01-04 with reprex v2.0.2

This stores the data as a Date object. If the end goal is to convert to 2022-01-16 00:04 for display, there are a couple of ways to do that, and the choice depends on whether need to make date calculations exists.


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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.