Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.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_Regex_Date_Sequence - Fatal编程技术网

R 使用特殊格式创建日期序列

R 使用特殊格式创建日期序列,r,regex,date,sequence,R,Regex,Date,Sequence,我想知道如何按以下格式创建日期序列:从“Jul 23 10:20”到“Jul 30 10:25”到“1”天 我尝试了以下方法但没有成功: seq.Date(as.Date("Jul 23 10:20"), as.Date("Jul 30 10:25"), length.out = 7) 要保留时间,您应该将其转换为实际日期时间,从中很容易构建一个每次增加1天的序列。您可以使用strftime将其格式化 strftime(seq(如POSIXct(“202

我想知道如何按以下格式创建日期序列:从
“Jul 23 10:20”
“Jul 30 10:25”
“1”

我尝试了以下方法但没有成功:

seq.Date(as.Date("Jul 23 10:20"), as.Date("Jul 30 10:25"), length.out = 7)

要保留时间,您应该将其转换为实际日期时间,从中很容易构建一个每次增加1天的序列。您可以使用
strftime
将其格式化

strftime(seq(如POSIXct(“2020-07-23 10:20”),by=“1天”,length.out=7),%b%e%H:%M)
#>[1]“Jul 23 10:20”“Jul 24 10:20”“Jul 25 10:20”“Jul 26 10:20”“Jul 27 10:20”
#>[6]“7月28日10:20”“7月29日10:20”

要保留时间,您应该将时间转换为实际日期时间,从中可以轻松构建一个每次增加1天的序列。您可以使用
strftime
将其格式化

strftime(seq(如POSIXct(“2020-07-23 10:20”),by=“1天”,length.out=7),%b%e%H:%M)
#>[1]“Jul 23 10:20”“Jul 24 10:20”“Jul 25 10:20”“Jul 26 10:20”“Jul 27 10:20”
#>[6]“7月28日10:20”“7月29日10:20”

我们可以通过转换为
日期
格式来获取日期

format(seq(as.POSIXct("Jul 23 10:20", format = "%b %d %H:%M" ),
      by = "1 day", length.out = 7), "%b %d %H:%M")
#[1] "Jul 23 10:20" "Jul 24 10:20" "Jul 25 10:20" "Jul 26 10:20" "Jul 27 10:20" "Jul 28 10:20" "Jul 29 10:20"

或使用
lubridate

library(lubridate)
format(as.POSIXct("Jul 23 10:20", format = '%b %d %H:%M') + days(0:4), "%b %d %H:%M")
#[1] "Jul 23 10:20" "Jul 24 10:20" "Jul 25 10:20" "Jul 26 10:20" "Jul 27 10:20"

我们可以通过转换为
Date
格式来获取日期

format(seq(as.POSIXct("Jul 23 10:20", format = "%b %d %H:%M" ),
      by = "1 day", length.out = 7), "%b %d %H:%M")
#[1] "Jul 23 10:20" "Jul 24 10:20" "Jul 25 10:20" "Jul 26 10:20" "Jul 27 10:20" "Jul 28 10:20" "Jul 29 10:20"

或使用
lubridate

library(lubridate)
format(as.POSIXct("Jul 23 10:20", format = '%b %d %H:%M') + days(0:4), "%b %d %H:%M")
#[1] "Jul 23 10:20" "Jul 24 10:20" "Jul 25 10:20" "Jul 26 10:20" "Jul 27 10:20"

你不想要长度。out=8吗?你不想要长度。out=8吗?@rnorouzian对不起,我在看你的输入,其中有两个inputs@rnorouzian抱歉,我正在查看您的输入,其中有两个输入