[英]Issue with hms difftime type in R
我有兩個非常相似的數據框,試圖將它們綁定在一起,但是遇到了問題。 我使用dput()從每個數據幀中捕獲3列(其中一個有問題)和10行。
str1 = structure(list(period_type = c("half", "half", "half", "half",
"half", "half", "half", "half", "half", "half"), period_number = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), clock = structure(c("72000",
"70800", "69720", "69600", "69480", "68280", "67200", "66780",
"65160", "65160"), class = c("hms", "difftime"), units = "secs")), row.names = c(NA,
10L), class = "data.frame")
str2 = structure(list(period_type = c("half", "half", "half", "half",
"half", "half", "half", "half", "half", "half"), period_number = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), clock = structure(c(72000,
71640, 70140, 70020, 69720, 69720, 69720, 69720, 69300, 67860
), class = c("hms", "difftime"), units = "secs")), row.names = c(NA,
10L), class = "data.frame")
> head(plyr::rbind.fill(str1, str2))
period_type period_number clock
1 half 1 NA:NA:NANA
2 half 1 NA:NA:NANA
3 half 1 NA:NA:NANA
4 half 1 NA:NA:NANA
5 half 1 NA:NA:NANA
6 half 1 NA:NA:NANA
當我執行rbind.fill
,時鍾列變成NA:NA:NANA,這令人沮喪。 當我檢查每個數據幀中clock
列的類時,它們“看起來”是相同的:
> class(str1$clock)
[1] "hms" "difftime"
> class(str2$clock)
[1] "hms" "difftime"
...但是,幸運的是dput()
向我揭示的是,時鍾向量中的值是str1的字符串和str2的數字。 再次,我沒有從頭開始創建這些demo str
數據幀,它們是從我的完整數據幀創建的,因此這在數據幀之間的clock
列中顯然是不同的。
我該如何解決這些問題,以使列類型保持一致? 提前致謝!!
這是不是真的,為什么解釋plyr::rbind.fill
沒有工作,但下面不工作
library(hms)
do.call(rbind, list(str1, str2))
# period_type period_number clock
#1 half 1 20:00:00
#2 half 1 19:40:00
#3 half 1 19:22:00
#4 half 1 19:20:00
#5 half 1 19:18:00
#6 half 1 18:58:00
#7 half 1 18:40:00
#8 half 1 18:33:00
#9 half 1 18:06:00
#10 half 1 18:06:00
#11 half 1 20:00:00
#12 half 1 19:54:00
#13 half 1 19:29:00
#14 half 1 19:27:00
#15 half 1 19:22:00
#16 half 1 19:22:00
#17 half 1 19:22:00
#18 half 1 19:22:00
#19 half 1 19:15:00
#20 half 1 18:51:00
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.