I have two dataframes that are very similar that I am trying to rbind together, but am running into an issue. I used dput() to grab 3 columns (one of which is problematic) and 10 rows from each dataframe.
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
When I perform rbind.fill
the clock column turns into NA:NA:NANA, which is frustrating. When I check the classes for the clock
column in each dataframe, they "appear" to be the same:
> class(str1$clock)
[1] "hms" "difftime"
> class(str2$clock)
[1] "hms" "difftime"
...however, what the dput()
has fortunately revealed to me is that the values in the clock vector are strings for str1 and numbers for str2. Again I did not create these demo str
dataframes from scratch, they are from my full dataframes, so this is clearly a different in the clock
column between dataframes.
How can I fix either of these so that the column types are consistent? Thanks in advance!!