Skip to content
Prev 336134 / 398513 Next

datetime and date

On 02/03/2014 12:53 PM, Yolande Tra wrote:
Hi Yolande,
Try this:

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

Notice that I think you got the month/day order wrong, if your first 
type is correct.

Jim