r - Preserve Date format after APPLY -
i have been trying convert character vector vector of dates. have vector called "dates" character. used function "lubridate" package convert posixct format. when individually convert each every element posixct , bind them using c(), desired output, i.e "dates_final".
when try use apply function same output, gives me numeric vector. there way preserve format while applying function?
this example. in original dataset, dates in different formats characters, have written custom function detects formats each every type of date , parses them, , outputs posixct format. if dates in same format in whole data not have been problem.
the data set has millions of records. cannot possibly use loop.
library(lubridate) dates <- c("01-05-2015 00:10","01-05-2015 00:15", "01-05-2015 00:15","01-05-2015 00:42") dates_actaul_1 <- dmy_hm(dates[1]) dates_actaul_2 <- dmy_hm(dates[2]) dates_actaul_3 <- dmy_hm(dates[3]) dates_actaul_4 <- dmy_hm(dates[4]) dates_final <- c(dates_actaul_1,dates_actaul_2,dates_actaul_3,dates_actaul_4) dates_final [1] "2015-05-01 05:40:00 ist" "2015-05-01 05:45:00 ist" [3] "2015-05-01 05:45:00 ist" "2015-05-01 06:12:00 ist" dates_applied <- apply(x = data.frame(dates),margin = 1,fun = dmy_hm) dates_applied [1] 1430439000 1430439300 1430439300 1430440920
Comments
Post a Comment