Adding missing rows

前端 未结 3 1637
旧巷少年郎
旧巷少年郎 2020-12-06 03:26

The format of my excel data file is:

 day                 value
 01-01-2000 00:00:00    4
 01-01-2000 00:01:00    3
 01-01-2000 00:02:00    1
 01-01-2000 00:         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-06 03:36

    This is now completely automated in the padr package. Takes only one line of code.

    original <- data.frame(
      day = as.POSIXct(c("01-01-2000 00:00:00",
                         "01-01-2000 00:01:00",
                         "01-01-2000 00:02:00",
                         "01-01-2000 00:04:00"), format="%m-%d-%Y %H:%M:%S"),
      value = c(4, 3, 1, 1))
    
    library(padr)
    library(dplyr) # for the pipe operator
    original %>% pad %>% fill_by_value(value)
    

    See vignette("padr") or this blog post for its working.

提交回复
热议问题