library(tidyverse)
library(lubridate)
library(padr)
df <- tibble(`Action Item ID` = c("ABC", "DEF", "GHI", "JKL", "MNO", "PQR"),
`Date Created` = as.Date(c("2019-01-01", "2019-01-01",
"2019-06-01", "2019-06-01",
"2019-08-01", "2019-08-01")),
`Date Closed` = as.Date(c("2019-01-15", "2019-05-31",
"2019-06-15", "2019-07-05",
"2019-08-15", NA)),
`Current Status` = c(rep("Closed", 5), "Open")) %>%
pivot_longer(-c(`Action Item ID`, `Current Status`),
names_to = "Type",
values_to = "Date")
#> # A tibble: 12 x 4
#> `Action Item ID` `Current Status` Type Date
#> <chr> <chr> <chr> <date>
#> 1 ABC Closed Date Created 2019-01-01
#> 2 ABC Closed Date Closed 2019-01-15
#> 3 DEF Closed Date Created 2019-01-01
#> 4 DEF Closed Date Closed 2019-05-31
#> 5 GHI Closed Date Created 2019-06-01
#> 6 GHI Closed Date Closed 2019-06-15
#> 7 JKL Closed Date Created 2019-06-01
#> 8 JKL Closed Date Closed 2019-07-05
#> 9 MNO Closed Date Created 2019-08-01
#> 10 MNO Closed Date Closed 2019-08-15
#> 11 PQR Open Date Created 2019-08-01
#> 12 PQR Open Date Closed NA
У меня есть мой фрейм данных выше, и я пытаюсь дополнить даты в каждой группе пакетом padr R.
df %>% group_by(`Action Item ID`) %>% pad()
#> Error: Not all grouping variables are column names of x.
Ошибка не имеет большого смысла для меня , Я ищу вывод, который будет выглядеть следующим образом:
#> # A tibble: ? x 4
#> `Action Item ID` `Current Status` Type Date
#> <chr> <chr> <chr> <date>
#> ABC Closed Date Created 2019-01-01
#> ABC NA NA 2019-01-02
#> ABC NA NA 2019-01-03
#> ... ... ... ...
#> ABC Closed Date Closed 2019-01-15
#> DEF Closed Date Created 2019-01-01
#> DEF NA NA 2019-01-02
#> ... ... ... ...
#> DEF NA NA 2019-05-30
#> DEF Closed Date Closed 2019-05-31
#> GHI Closed Date Created 2019-06-01
#> ... ... ... ...
Кто-нибудь есть какие-либо идеи, что пошло не так?