Re: [R] parsing DOB data

2020-04-17 Thread Jim Lemon
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))

Re: [R] parsing DOB data

2020-04-16 Thread Jim Lemon
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(

Re: [R] parsing DOB data

2020-04-16 Thread Pär Leijonhufvud
5 april 2020 20:31 To: r-help@r-project.org Subject: [R] parsing DOB data I have a data set (.csv) with date (eg date of birth) information stored as character vectors that I’m attempting to transform to POSIXct objects using the package lubridate (1.7.4). The problem that I’m trying to address is tha

[R] parsing DOB data

2020-04-16 Thread Peter Nelson via R-help
I have a data set (.csv) with date (eg date of birth) information stored as character vectors that I’m attempting to transform to POSIXct objects using the package lubridate (1.7.4). The problem that I’m trying to address is that my two digit years are invariably (?) parsed to 20xx. For example,