Skip to content

Instantly share code, notes, and snippets.

@ramhiser
Created August 18, 2011 21:27
Show Gist options
  • Save ramhiser/1155263 to your computer and use it in GitHub Desktop.
Save ramhiser/1155263 to your computer and use it in GitHub Desktop.
Error when using lubridate
# The Error
> mdy_hms(my_dates)
Error in data.frame(c("14", "19", "01"), c("14", "20"), check.names = TRUE, :
arguments imply differing number of rows: 3, 2
# The Cause
> str_split(dates, fixed(sep[1]))
[[1]]
[1] "14" "19" "01"
[[2]]
[1] "14" "20"
# The Culprit - The following code is in the hms() call, which is called in mdy_hms().
> as.data.frame(str_split(dates, fixed(sep[1])))
Error in data.frame(c("14", "19", "01"), c("14", "20"), check.names = TRUE, :
arguments imply differing number of rows: 3, 2
> dput(my_dates)
c("8/18/2011 14:19:01", "8/18/2011 14:20")
> dput(sep)
":"
# The dates in this case are really the times, but I named them 'dates' to correspond to the code within hms().
> dput(dates)
structure(c("14:19:01", "14:20"), .Names = c("c..8.18.2011....14.19.01..",
"c..8.18.2011....14.20.."))
> sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: x86_64-pc-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] stringr_0.4 lubridate_0.2.5 ggplot2_0.8.9 proto_0.3-9.2 reshape_0.8.4 plyr_1.5.2
loaded via a namespace (and not attached):
[1] tools_2.13.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment