[英]convert characters to month and year ( date ) in R
How do I convert a string "Apr-16" to Month
April of 2016 ? 我如何将字符串转换为“APR-16”到
Month
的2016年4月?
I tired as.Date(x, format ..)
, that isn't helping . 我累了
as.Date(x, format ..)
,这没有帮助。
What options do I have here ? 我在这里有什么选择?
x <- "Apr-16"
x <- as.Date(paste0("1-",x),format="%d-%b-%y")
format(x,"%B of %Y")
[1] "April of 2016"
Another option is regex
另一个选择是
regex
sub("-", "il of 20", x)
#[1] "April of 2016"
Or using yearmon
from zoo
或使用
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.