Skip to content
Prev 336135 / 398513 Next

datetime and date

On 02/03/2014 01:08 PM, Jim Lemon wrote:
Hi Yolande,
Oops, major error. Change the name of the variable or you won't get the 
second lot of dates:

# first get the dates with times
df$Date2<-
  as.POSIXct(as.character(df$Date1, format = "%m/%d/%Y %H:%M:%S"))
# then fill in the ones without times
df$Date2[nchar(df$Date1) < 10]<-
  as.POSIXct(as.character(df$Date1, format = "%m/%d/%y"))

Jim