我對Hadley的「rbind.fill」函數的行爲感到困惑。我有一個數據框的列表,我想對其執行一個簡單的rbind操作,但是rbind.fill函數給了我無法解釋的結果。請注意,「rbind」函數確實給了我期望的輸出。下面是小例子:意外的「rbind.fill」行爲
library(reshape)
data1 <- structure(list(DATE = structure(c(1277859600, 1277856000), class = c("POSIXct",
"POSIXt"), tzone = "GMT"), BACK = c(0, -1)), .Names = c("DATE",
"BACK"), row.names = 1:2, class = "data.frame")
data2 <- structure(list(DATE = structure(c(1277856000, 1277852400), class = c("POSIXct",
"POSIXt"), tzone = "GMT"), BACK = c(0, -1)), .Names = c("DATE",
"BACK"), row.names = 1:2, class = "data.frame")
bind1 <- rbind.fill(list(data1, data2))
bind2 <- rbind(data1, data2)
data1
data2
bind1
bind2
DATE BACK
1 2010-06-30 01:00:00 0
2 2010-06-30 00:00:00 -1
DATE BACK
1 2010-06-30 00:00:00 0
2 2010-06-29 23:00:00 -1
DATE BACK
1 2010-06-29 18:00:00 0
2 2010-06-29 17:00:00 -1
3 2010-06-29 17:00:00 0
4 2010-06-29 16:00:00 -1
DATE BACK
1 2010-06-30 01:00:00 0
2 2010-06-30 00:00:00 -1
3 2010-06-30 00:00:00 0
4 2010-06-29 23:00:00 -1
因此,大家可以看到,bind1
其中包含rbind.fill
輸出會在DATE
列甚至沒有在原數據集中的新時代。這是預期的行爲?我知道我可以簡單地使用
bind <- do.call(rbind, list(data1, data2))
來綁定我擁有的5000+數據框,但任何人都可以對上述行爲說話嗎?
謝謝。正如@DWin指出的,這不是rbind.fill函數本身的問題,但是在輸出中,時間是在太平洋時間打印的,但是格式是GMT格式。
SessionInfo()
R version 2.12.1 (2010-12-16)
Platform: x86_64-pc-mingw32/x64 (64-bit)
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] tcltk grid stats graphics grDevices utils datasets methods
[9] base
other attached packages:
[1] tcltk2_1.1-5 reshape_0.8.4 plyr_1.4 proto_0.3-9.1
loaded via a namespace (and not attached):
[1] ggplot2_0.8.9 tools_2.12.1
我無法複製此行爲。你的'sessionInfo()'是什麼? – 2011-05-23 17:39:46
看起來,正如DWin指出的那樣(以及您似乎期待的),這是一個時區問題,並且僅與rbind.fill函數本身(我假設它在某處內使用「print.POSIXct」)間接相關 – Rguy 2011-05-23 18:22:19