i have shiny app requires input cvs (utf-16) file gets downloaded system. depending on whether user uploads file directly download folder on local machine or user opens file in excel, saves on local machine, , uploads shiny, uploads different date field format.
in order give robust solution user problem, tried following customized function:
.asdate <- function(x) { if(nchar(x) < 20) { as.posixct(strptime(x, "%y/%m/%d %h:%m")) } else { as.posixct(strptime(x, "%b %d, %y %i:%m:%s %p")) } } but, when sapply against column, numeric output:
foo <- data.frame(start.time = c("2012/02/06 15:47", "2012/02/06 15:02", "2012/02/22 10:08"), duration = c(1,2,3), stringsasfactors = f) sapply(foo$start.time, .asdate) 2012/02/06 15:47 2012/02/06 15:02 2012/02/22 10:08 1.3e+09 1.3e+09 1.3e+09 instead of correct conversion i'm looking for:
as.posixct(strptime(foo$start.time, "%y/%m/%d %h:%m")) [1] "2012-02-06 15:47:00 est" "2012-02-06 15:02:00 est" "2012-02-22 10:08:00 est" could correcting issue?
sapply returns vector , converting dates numeric class. tried using lapply , returned output looking for:
lapply(foo$start.time, .asdate) or can use function created:
yourdates<-.asdate(foo$start.time) if keen on using sapply following(which same lapply):
sapply(foo$start.time, .asdate, simplify = f, use.names = f)
Comments
Post a Comment