Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I've got weird results when I try to convert an interval as a period and compute the length of the period in months.
I use lubridate and magrittr
> library(lubridate) > library(magrittr)
I take as interval the time period between 2012, Jan 1st and 2013, Jan 1st.
When I try to compute the length of the period in days. I've got expected value 325.25 :
> interval(start = ymd("2012-01-01"), end = ymd("2013-01-01")) %>% as.period() %>% as.numeric("days") [1] 365.25
When I try to compute the length of the period in years, I've got the expected value 1 :
> interval(start = ymd("2012-01-01"), end = ymd("2013-01-01")) %>% as.period() %>% as.numeric("years") [1] 1
But when I try to compute the length in months, I've got the inverse of the expected value :
> interval(start = ymd("2012-01-01"), end = ymd("2013-01-01")) %>% as.period() %>% as.numeric("months") [1] 0.08333333
Note that
> 1/0.08333333 [1] 12
So the outcome is one over the expected value.
Is it a bug ? Am I doing something wrong in my code ?
> library(devtools) > session_info() Session info ------------------------------------------------------------------- setting value version R version 3.3.1 (2016-06-21) system x86_64, linux-gnu ui X11 language (EN) collate fr_FR.utf8 tz Europe/Paris date 2016-10-28 Packages ----------------------------------------------------------------------- package * version date source devtools * 1.12.0 2016-06-24 CRAN (R 3.3.1) digest 0.6.10 2016-08-02 CRAN (R 3.3.1) lubridate * 1.6.0 2016-09-13 CRAN (R 3.3.1) magrittr * 1.5 2014-11-22 CRAN (R 3.3.0) memoise 1.0.0 2016-01-29 CRAN (R 3.3.0) stringi 1.1.1 2016-05-27 CRAN (R 3.3.0) stringr 1.1.0 2016-08-19 CRAN (R 3.3.1) withr 1.0.2 2016-06-20 CRAN (R 3.3.1)
The text was updated successfully, but these errors were encountered:
This is a bug. Thanks.
But you should be using time_length instead:
time_length
int <- interval(start = ymd("2012-01-01"), end = ymd("2013-01-01")) time_length(int, "year") time_length(int, "month")
Sorry, something went wrong.
697e01e
Merge pull request #524 from timgoodman/master
c5ddda2
[Fix #490] Correctly compute length of period in months
No branches or pull requests
I've got weird results when I try to convert an interval as a period and compute the length of the period in months.
I use lubridate and magrittr
I take as interval the time period between 2012, Jan 1st and 2013, Jan 1st.
When I try to compute the length of the period in days. I've got expected value 325.25 :
When I try to compute the length of the period in years, I've got the expected value 1 :
But when I try to compute the length in months, I've got the inverse of the expected value :
Note that
So the outcome is one over the expected value.
Is it a bug ? Am I doing something wrong in my code ?
The text was updated successfully, but these errors were encountered: