Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

R seq.Date() Function - Generating Date Sequences

R seq.Date() Function - Generating Date Sequences

R Language Examples R Language Examples

The R seq.Date() function is used to generate sequences of dates at regular intervals.

In time series analysis and periodic report generation, creating date sequences is a very common requirement.

The syntax of the seq.Date() function is as follows:

seq(from, to, by = "days")

Parameter Description:

Example

This week's date sequence

start

<-

as.Date

(

"2026-05-11"

)

week_dates

<-

seq

(

start

,

by

=

"days"

, length.

out

=

7

)

print

(

"This week's dates:"

)

print

(

week_dates

)

The first day of each month

month_starts

<-

seq

(

as.Date

(

"2026-01-01"

)

,

                   

as.Date

(

"2026-12-01"

)

,

                   

by

=

"months"

)

print

(

"First day of each month:"

)

print

(

month_starts

)

The output of the code above is:

[1] "本周日期:"

[1] "2026-05-11" "2026-05-12" "2026-05-13" "2026-05-14"

[5] "2026-05-15" "2026-05-16" "2026-05-17"

[1] "每月第一天:"

 [1] "2026-01-01" "2026-02-01" "2026-03-01" "2026-04-01"

 [5] "2026-05-01" "2026-06-01" "2026-07-01" "2026-08-01"

 [9] "2026-09-01" "2026-10-01" "2026-11-01" "2026-12-01"

R Language Examples R Language Examples