0

I have a data frame (CSV file) that consists of date and time with 5 minutes interval. I want to change it to 1 minutes interval using R.

It looks like this currently:

7/2/19 13:30
7/2/19 13:35
7/2/19 13:40
7/2/19 13:45
7/2/19 13:50

..... it has many rows

Can it be changed to the following format?

7/2/19 13:30
7/2/19 13:31
7/2/19 13:32
7/2/19 13:33
7/2/19 13:34
7/2/19 13:35
7/2/19 13:36
7/2/19 13:37
7/2/19 13:38
7/2/19 13:39
7/2/19 13:40
7/2/19 13:41
7/2/19 13:42
7/2/19 13:43
7/2/19 13:44

I think some type of loop must be used and I am a newbie at using R. I would be thankful if friends at this portal could help me solve this problem.

M--
  • 25,431
  • 8
  • 61
  • 93
  • 3
    We can do, `library(tidyverse);library(lubridate); df1 %>% mutate(datetime = mdy_hms(datetime) %>% complete(datetime = format(seq(first(datetime), last(datetime), bv = "1 min"), "%m/%d/%Y %H:%M"))` – akrun Jul 08 '19 at 20:31
  • 1
    Pretty sure this is a duplicate. There is a seq method for date time vectors. – IRTFM Jul 08 '19 at 20:43
  • Possible duplicate of [Insert rows for missing dates/times](https://stackoverflow.com/questions/16787038/insert-rows-for-missing-dates-times) – divibisan Jul 08 '19 at 22:16
  • @akrun Thanks for the code bro. But it is not working. It shows some error. If possible, please check the code. – user11570034 Jul 09 '19 at 20:16

0 Answers0