拆分一个字符并在R中添加其他字符串

时间:2016-05-19 20:15:43

标签: r string character

我有以下字符selectedMonths <- c("201501")

如何获得两个字符串

"2015-01-01 00:00:00" 

"2015-01-31 23:59:59"

1 个答案:

答案 0 :(得分:1)

尝试

library(zoo)
paste(as.Date(as.yearmon(selectedMonths, format = '%Y%m')), "00:00:00")
paste(as.Date(as.yearmon(selectedMonths, format = '%Y%m'), frac = 1), "23:59:59")

给出了:

#[1] "2015-01-01 00:00:00"
#[1] "2015-01-31 23:59:59"