Convert date to character in particular format In R

谁说胖子不能爱 提交于 2019-12-10 20:06:05

问题


I need to map 3-4 different dataframes that have different date formats. How can we convert date in format:

YYYY-MM-DD

to character in the format:

MMM-YY

回答1:


Create a date object from the string (skip this if your column is already in the Date format):

original_date <- as.Date("2017-07-19", "%Y-%m-%d")

Then format the original date to the new format:

format(original_date, "%b-%y")   
# "Jul-17"

The %b indicates the 3-letter abbreviation of the month and %y is the year without the century. You can find more of these codes and their meaning here: http://strftime.org/



来源:https://stackoverflow.com/questions/45191025/convert-date-to-character-in-particular-format-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!