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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -