-2

I have a folder with manys excel, two types formats DATETIME :

  • the date after imported by read.csv2, type FACTOR YYYY-MM-DD HH: MM: SS
  • and other excel format type FACTOR, format DD/MM/YYYY HH: MM.

I want only one code to walk both types excel: Finally with the same format YYYY-MM-DD HH: MM: SS to import

i don't know how to do it.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213

1 Answers1

1

We can do this with anytime. Check whether the desired format is already there by checking getFormats(). If the format is not present, use addFormats to add the specific format and then convert to DateTime with anytime

library(anytime)
addFormats("%d/%m/%Y %H:%M")
anytime(c("2015-03-15 03:15:25", "25/05/1976 05:25"))
#[1] "2015-03-15 03:15:25 IST" "1976-05-25 05:25:00 IST"
akrun
  • 874,273
  • 37
  • 540
  • 662