Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
拆分一个字符并在R中添加其他字符串_R_String_Character - Fatal编程技术网

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

拆分一个字符并在R中添加其他字符串,r,string,character,R,String,Character,我有以下字符selectedMonthsTry 其中: #[1] "2015-01-01 00:00:00" #[1] "2015-01-31 23:59:59" 你需要更详细地解释你的问题。在将一个字符串转换为另一个字符串时,您希望做哪些假设?可能重复的I只有字符“201501”,表示2015年1月。第一部分是2015年,最后两部分是月份(本例中为1月)。我想将给定的字符“201501”拆分为“2015-01”,然后我需要将其添加到“2015-01-01 00:00:00”和其他“2015-

我有以下字符
selectedMonthsTry

其中:

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

你需要更详细地解释你的问题。在将一个字符串转换为另一个字符串时,您希望做哪些假设?可能重复的I只有字符“201501”,表示2015年1月。第一部分是2015年,最后两部分是月份(本例中为1月)。我想将给定的字符“201501”拆分为“2015-01”,然后我需要将其添加到“2015-01-01 00:00:00”和其他“2015-01-31 23:59:59”
"2015-01-31 23:59:59"
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"