Convert date to character in particular format In R

后端 未结 1 1291
离开以前
离开以前 2021-02-20 06:23

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 form

1条回答
  •  [愿得一人]
    2021-02-20 06:46

    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/

    0 讨论(0)
提交回复
热议问题