-
Notifications
You must be signed in to change notification settings - Fork 417
Closed
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behaviorrectangling 🗄️converting deeply nested lists into tidy data framesconverting deeply nested lists into tidy data frames
Description
Hi, i try unnesting date column by unnest_longer()
, and get do not know how to convert 'value' to class “Date”
, but its works when i use
unnest()`
data example
# package
library(dplyr)
library(tidyr)
library(lubridate)
# test frame
df <- data.frame(
transaction_id = c("1", "2"),
trade_date = as.Date(c("2019-07-01", "2019-08-01")),
start = as.Date(c("2019-08-01", "2019-12-01")),
end = as.Date(c("2019-10-31", "2020-02-28")),
price = c(5, 6),
currency = c("CAD", "CAD"),
volume = c(10000, 5000)
)
unnest_longer example
# unnest_longer
df %>%
group_by(transaction_id) %>%
mutate(start=list(seq(start, end, "months"))) %>%
unnest_longer(col=start)
Result:
Error in as.Date.default(value) :
do not know how to convert 'value' to class “Date”
unnest example
# unnest
df %>%
group_by(transaction_id) %>%
mutate(start=list(seq(start, end, "months"))) %>%
unnest(col=start)
Result: OK
It`is normal behavior?
sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=Russian_Ukraine.1251 LC_CTYPE=Russian_Ukraine.1251 LC_MONETARY=Russian_Ukraine.1251 LC_NUMERIC=C
[5] LC_TIME=Russian_Ukraine.1251
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] lubridate_1.7.9 stringr_1.4.0 zoo_1.8-8 googlesheets4_0.2.0.9000 dplyr_1.0.2
[6] tidyr_1.1.2
loaded via a namespace (and not attached):
[1] tidyselect_1.1.0 xfun_0.18 remotes_2.2.0 purrr_0.3.4 gargle_0.5.0.9000 lattice_0.20-41 vctrs_0.3.6
[8] generics_0.1.0 testthat_2.3.2 usethis_1.6.3 htmltools_0.5.0 yaml_2.2.1 utf8_1.1.4 rlang_0.4.9
[15] pkgbuild_1.1.0 pillar_1.4.7 glue_1.4.2 withr_2.3.0 sessioninfo_1.1.1 lifecycle_0.2.0 cellranger_1.1.0
[22] devtools_2.3.2 memoise_1.1.0 evaluate_0.14 knitr_1.30 callr_3.5.1 ps_1.4.0 curl_4.3
[29] fansi_0.4.1 Rcpp_1.0.5 openssl_1.4.3 backports_1.1.10 desc_1.2.0 pkgload_1.1.0 jsonlite_1.7.2
[36] fs_1.5.0 googleAuthR_1.3.0 askpass_1.1 digest_0.6.27 stringi_1.5.3 processx_3.4.4 rprojroot_1.3-2
[43] grid_4.0.3 cli_2.2.0 tools_4.0.3 magrittr_2.0.1 tibble_3.0.4 crayon_1.3.4 pkgconfig_2.0.3
[50] ellipsis_0.3.1 prettyunits_1.1.1 googledrive_1.0.1 assertthat_0.2.1 rmarkdown_2.4 httr_1.4.2 rstudioapi_0.11
[57] R6_2.5.0 compiler_4.0.3
Metadata
Metadata
Assignees
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behaviorrectangling 🗄️converting deeply nested lists into tidy data framesconverting deeply nested lists into tidy data frames