1
我需要日期列轉換爲不同的格式R.格式現有的日期列不同的格式中的R
數據:
Year Plant_Date
2010 May-08-2010
2010 Apr-09-2010
2010 June-02-2010
輸出:
Year Plant_Date
2010 05/08/2010
2010 04/09/2010
2010 06/02/2010
怎麼辦這在R?
我需要日期列轉換爲不同的格式R.格式現有的日期列不同的格式中的R
數據:
Year Plant_Date
2010 May-08-2010
2010 Apr-09-2010
2010 June-02-2010
輸出:
Year Plant_Date
2010 05/08/2010
2010 04/09/2010
2010 06/02/2010
怎麼辦這在R?
查看as.Date
函數的文檔,然後在日期對象上使用format
函數(例如%Y是4位年份,%d是日期,%b是月份縮寫)。我假設「六月」是「君」,因爲其他月份是縮寫:
# the raw strings:
> (inString <- c("May-08-2010", "Apr-09-2010", "Jun-02-2010"))
[1] "May-08-2010" "Apr-09-2010" "Jun-02-2010"
# convert to date object:
> (inDates <- as.Date(inDates, format = "%b-%d-%Y"))
[1] "2010-05-08" "2010-04-09" "2010-06-02"
# format using format function:
> format(inDates, "%m/%d/%Y")
[1] "05/08/2010" "04/09/2010" "06/02/2010"