3
I have 236 files in . csv that have all the same columns. My goal is to join them all into one data frame only.
However, each of them has 4 columns with date and time values. The problem is in the columns referring to date and time. Some dates are in format YYYY-MM-DD HH:MM:SS
, as 2019-10-08 10:15:00
. Other dates are in format DD/MM/YYYY HH:MM
, as 01/08/2001 21:56
.
For the first case, I would use the function ymd_hms
package lubridate
to create a Posixct object:
library(lubridate)
ymd_hms("2019-10-08 10:15:00")
[1] "2019-10-08 10:15:00 UTC"
For the second case, I would use the function dmy_hm
of the same package to get the result I wish:
dmy_hm("01/08/2001 21:56")
[1] "2001-08-01 21:56:00 UTC"
But how to precede in the case where I have the two date formats, still as characters, in the same vector? In other words, how to convert the character array x
, given below
x <- c("2019-10-08 10:15:00", "01/08/2001 21:56")
on a vector of type Posixct?