Skip to content
New issue

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

Feature Request: Add a cutoff year to decide if 21th century or not #560

Closed
skanskan opened this issue Jun 29, 2017 · 0 comments

Comments

@skanskan
Copy link

commented Jun 29, 2017

Hello.

It would be nice to have a cutoff parameter for commands such as dmy().
It's quite common to deal with dates stored as 31-12-40 or 12/31/70 where the year is stored with just 2 digits. That's a bad way to do it but there are many databases like that.

If you just use lubruidate commands to convert that strings to dates the user can get unexpected results.
And what's more serious, it can even miss he is having a problem till is too late.

The user can transform the data by doing:

mydates <- dmy(mydates)
yyy <- year(mydates) %% 100  
year(mydates) <- ifelse(yyy > 20, 1900+yyy, 2000+yyy)

or

dmy(paste0(sub("\\d\\d$","",xxx) , ifelse( (tt <- 
   sub("\\d\\d-\\D\\D\\D-","",xxx)  ) > 20 ,paste0("19",tt),paste0("20",tt))))

But this would need to be modyfied depending on the exact formats the user has and wants, and it's prone to error and takes a lot of code for a simple task.

Could you please add a "cutoff" date parameter to lubridate functions to allow the user to just do dmy(mydates, cutoff=20) when he wants to consider numbers bellow 20 as 20xx and numbers above 20 as 19xx, please?

I think it should be easy because somewhere you already do it, you just need to expose that parameter to the user.
And I think it would be very useful.
I will also allow to easily use the same syntax across different libraries.

@vspinu vspinu closed this in aefc121 Oct 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.