Hi Peter,
I worked out a neat function to add the century to short dates. It
works fine on its own, but sadly it bombs when used with sapply. Maybe
someone else can point out my mistake:
add_century<-function(x,changeover=68,previous=19,current=20,pos=1,sep="-") {
xsplit<-unlist(strsplit(x,sep))
Hi Peter,
One way is to process the strings before converting them to dates:
x2<-c("45-12-03","01-06-24","04-9-15","1901-03-04")
add_century<-function(x,changeover=68,previous=19,current=20) {
centuries<-sapply(sapply(x,strsplit,"-"),"[",1)
shortyears<-which(!(nchar(centuries)>2))
century<-rep(
Hi!
For more solutions look at
https://stackoverflow.com/questions/33221603/r-lubridate-returns-unwanted-century-when-given-two-digit-year
The proposed solution:
some_dates <- c("3/18/75", "March 10, 1994", "10/1/80", "June 15, 1979")
dates <- mdy(some_dates)
future_dates <- year(dates
3 matches
Mail list logo