2016年6月14日火曜日

Calculate # of months from the beginning of the year.

change language setting causes in other parts of system. the example is below.

> m <- as.numeric(months(Sys.Date(),abbreviate = T)) 

in JA environment, this operation returns 6 in June but ,in EN , months returns "Jun" and it is unable to process in as.numeirc. This breaks operations in the latter parts.

The fix is to use MonthsBetween and mondate in mondate library. They should be independent from language setting.

m <- ceiling(MonthsBetween(mondate("2016-01-01"),mondate(Sys.Date()))) ;
> m
[1] 6
attr(,"timeunits")
[1] "months"




0 件のコメント: