How can I reformat a series of dates in a vector in R -


i have vector of dates i'm trying convert date i'm not getting expected output, when sapply as.date instead of getting series of reformatted dates names dates , odd value.

dates = c("20-mar-2015", "25-jun-2015", "23-sep-2015", "22-dec-2015") sapply(dates, as.date, format = "%d-%b-%y") 20-mar-2015 25-jun-2015 23-sep-2015 22-dec-2015        16514       16611       16701       16791  

i each of values in vector showing new formated value. e.g. happen if as.date shown applied each element

as.date("20-mar-2015", format = "%d-%b-%y") [1] "2015-03-20" 

you can directly use as.date(dates, format = "%d-%b-%y"). as.date vectorized, i.e. can take vector input, not single entry.

in case:

dates <- c("20-mar-2015", "25-jun-2015", "23-sep-2015", "22-dec-2015") as.date(dates, format = "%d-%b-%y") # [1] "2015-03-20" "2015-06-25" "2015-09-23" "2015-12-22" 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -