我有两个非常相似的数据框,我试图将它们绑定在一起,但遇到了问题。我使用 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 的数字。同样,我没有str
从头开始创建这些演示数据框,它们来自我的完整数据框,因此这clock
在数据框之间的列中显然是不同的。
如何修复其中任何一个以使列类型保持一致?提前致谢!!