簡體   English   中英

將字符轉換為R中的月份和年份(日期)

[英]convert characters to month and year ( date ) in R

我如何將字符串轉換為“APR-16”到Month的2016年4月?

我累了as.Date(x, format ..) ,這沒有幫助。

我在這里有什么選擇?

x <- "Apr-16"
x <- as.Date(paste0("1-",x),format="%d-%b-%y")
format(x,"%B of %Y")
[1] "April of 2016"

另一個選擇是regex

sub("-", "il of 20", x)
#[1] "April of 2016"

或使用zoo yearmon

library(zoo)
format(as.Date(as.yearmon(x, "%b-%y")), "%B of %Y")
#[1] "April of 2016"

數據

x <- "Apr-16"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM