round_date() 不适用于特定的 POSIXct object
round_date() not working for a specific POSIXct object
我认为这是 lubridate
包中 round_date()
中的错误,但我想确定一下。
这个有效:
round_date(as.POSIXct("2016-10-16 01:00:19", tz = "BRST"))
[1] "2016-10-16 01:00:19 BRST"
这行不通(我只是将参数单位设置为"week"):
round_date(as.POSIXct("2016-10-16 01:00:19", tz = "BRST"), unit = "week")
[1] NA
这是一个错误还是我遗漏了什么?
谢谢。
Session 信息:
> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server >= 2012 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dplyr_0.5.0 tidyr_0.6.0 tibble_1.2
[4] tidyverse_1.0.0 readr_1.0.0 csutils_0.1.0
[7] knitr_1.15.1 DT_0.2 forcats_0.1.1
[10] purrr_0.2.2 ggrepel_0.6.3 ggplot2_2.1.0
[13] stringi_1.1.2 lubridate_1.6.0 magrittr_1.5
[16] randomForest_4.6-12 RevoUtilsMath_10.0.0 RevoUtils_10.0.2
[19] RevoMods_10.0.0 MicrosoftML_1.0.0 mrsdeploy_1.0
[22] RevoScaleR_9.0.1 lattice_0.20-34 rpart_4.1-10
[25] DBI_0.5-1 RODBC_1.3-14
loaded via a namespace (and not attached):
[1] Rcpp_0.12.7 plyr_1.8.4 iterators_1.0.8
[4] tools_3.3.2 digest_0.6.10 jsonlite_1.1
[7] mrupdate_1.0.0 gtable_0.2.0 foreach_1.4.3
[10] CompatibilityAPI_1.1.0 curl_2.2 stringr_1.1.0
[13] htmlwidgets_0.7 grid_3.3.2 R6_2.2.0
[16] scales_0.4.0 codetools_0.2-15 htmltools_0.3.5
[19] assertthat_0.1 colorspace_1.2-7 lazyeval_0.2.0
[22] munsell_0.4.3
我认为您需要指定 tz=
参数
x <- as.POSIXct("2016-10-16 01:00:19")
y <- as.POSIXct("2016-10-16 01:00:19", tz = 'BRST')
> lubridate::round_date(x, 'week')
[1] NA
> lubridate::round_date(y, 'week')
[1] "2016-10-16 BRST"
>
区别就在这里:
> attributes(x)
$class
[1] "POSIXct" "POSIXt"
$tzone
[1] ""
> attributes(y)
$class
[1] "POSIXct" "POSIXt"
$tzone
[1] "BRST"
如果 unit=
参数不是秒、分、时或日,lubridate::round_date
会尝试在某处获取此属性。
我认为这是 lubridate
包中 round_date()
中的错误,但我想确定一下。
这个有效:
round_date(as.POSIXct("2016-10-16 01:00:19", tz = "BRST"))
[1] "2016-10-16 01:00:19 BRST"
这行不通(我只是将参数单位设置为"week"):
round_date(as.POSIXct("2016-10-16 01:00:19", tz = "BRST"), unit = "week")
[1] NA
这是一个错误还是我遗漏了什么? 谢谢。
Session 信息:
> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server >= 2012 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dplyr_0.5.0 tidyr_0.6.0 tibble_1.2
[4] tidyverse_1.0.0 readr_1.0.0 csutils_0.1.0
[7] knitr_1.15.1 DT_0.2 forcats_0.1.1
[10] purrr_0.2.2 ggrepel_0.6.3 ggplot2_2.1.0
[13] stringi_1.1.2 lubridate_1.6.0 magrittr_1.5
[16] randomForest_4.6-12 RevoUtilsMath_10.0.0 RevoUtils_10.0.2
[19] RevoMods_10.0.0 MicrosoftML_1.0.0 mrsdeploy_1.0
[22] RevoScaleR_9.0.1 lattice_0.20-34 rpart_4.1-10
[25] DBI_0.5-1 RODBC_1.3-14
loaded via a namespace (and not attached):
[1] Rcpp_0.12.7 plyr_1.8.4 iterators_1.0.8
[4] tools_3.3.2 digest_0.6.10 jsonlite_1.1
[7] mrupdate_1.0.0 gtable_0.2.0 foreach_1.4.3
[10] CompatibilityAPI_1.1.0 curl_2.2 stringr_1.1.0
[13] htmlwidgets_0.7 grid_3.3.2 R6_2.2.0
[16] scales_0.4.0 codetools_0.2-15 htmltools_0.3.5
[19] assertthat_0.1 colorspace_1.2-7 lazyeval_0.2.0
[22] munsell_0.4.3
我认为您需要指定 tz=
参数
x <- as.POSIXct("2016-10-16 01:00:19")
y <- as.POSIXct("2016-10-16 01:00:19", tz = 'BRST')
> lubridate::round_date(x, 'week')
[1] NA
> lubridate::round_date(y, 'week')
[1] "2016-10-16 BRST"
>
区别就在这里:
> attributes(x)
$class
[1] "POSIXct" "POSIXt"
$tzone
[1] ""
> attributes(y)
$class
[1] "POSIXct" "POSIXt"
$tzone
[1] "BRST"
如果 unit=
参数不是秒、分、时或日,lubridate::round_date
会尝试在某处获取此属性。