【发布时间】:2018-03-10 19:08:05
【问题描述】:
我正在尝试通过 POSIXct 列合并两个数据框。我正在使用 tidyverse 和 lubridate。 inner_join() 返回一个空数据帧,而 full_join() 返回较短帧的副本。这是一个错误还是有更合适或首选的方法来加入 POSIX 对象?
> library(tidyverse)
> library(lubridate)
> d1 <- tibble(date = as.POSIXct(seq(Sys.time() - days(1), Sys.time(), by = "min"), tz = "America/New_York"))
> head(d1)
# A tibble: 6 x 1
date
<dttm>
1 2018-03-09 14:01:34
2 2018-03-09 14:02:34
3 2018-03-09 14:03:34
4 2018-03-09 14:04:34
5 2018-03-09 14:05:34
6 2018-03-09 14:06:34
> d2 <- tibble(date = as.POSIXct(seq(Sys.time() - days(2), Sys.time(), by = "min"), tz = "America/New_York"))
> head(d2)
# A tibble: 6 x 1
date
<dttm>
1 2018-03-08 14:01:55
2 2018-03-08 14:02:55
3 2018-03-08 14:03:55
4 2018-03-08 14:04:55
5 2018-03-08 14:05:55
6 2018-03-08 14:06:55
> data <- inner_join(d1, d2, by = "date")
> head(data)
# A tibble: 0 x 1
# ... with 1 variable: date <dttm>
> data <- inner_join(d1, d2, by = "date")
> head(data)
# A tibble: 0 x 1
# ... with 1 variable: date <dttm>
> data <- merge(d1, d2, by = "date")
> dim(data)
[1] 0 1
> sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.3
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] lubridate_1.7.3 forcats_0.3.0 stringr_1.3.0 dplyr_0.7.4 purrr_0.2.4 readr_1.1.1 tidyr_0.8.0
[8] tibble_1.4.2 ggplot2_2.2.1 tidyverse_1.2.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.15 cellranger_1.1.0 pillar_1.2.1 compiler_3.4.2 plyr_1.8.4 bindr_0.1
[7] tools_3.4.2 jsonlite_1.5 nlme_3.1-131.1 gtable_0.2.0 lattice_0.20-35 pkgconfig_2.0.1
[13] rlang_0.2.0 psych_1.7.8 cli_1.0.0 rstudioapi_0.7 yaml_2.1.18 parallel_3.4.2
[19] haven_1.1.1 bindrcpp_0.2 xml2_1.2.0 httr_1.3.1 hms_0.4.1 grid_3.4.2
[25] glue_1.2.0 R6_2.2.2 readxl_1.0.0 foreign_0.8-69 modelr_0.1.1 reshape2_1.4.3
[31] magrittr_1.5 scales_0.5.0 rvest_0.3.2 assertthat_0.2.0 mnormt_1.5-5 colorspace_1.3-2
[37] stringi_1.1.6 lazyeval_0.2.1 munsell_0.4.3 broom_0.4.3 crayon_1.3.4
【问题讨论】:
-
我觉得日期不一样。