Dates and Time Series
Monthly Sequence
Regular Dates
seq.Date creates regular calendar sequences. A month step controls how far each generated date advances.
Program
Play the script to change the month step and compare the generated labels.
monthly_sequence.R
Replay: real traced execution (multi-file project)
start <- as.Date("2026-01-01")
month_step <- 1
dates <- seq.Date(start, by = paste(month_step, "month"), length.out = 4)
labels <- format(dates, "%b")
summary <- paste(labels, collapse = ",")
cat(summary, "\n", sep = "")
start <- as.Date("2026-01-01")
month_step <- 2
dates <- seq.Date(start, by = paste(month_step, "month"), length.out = 4)
labels <- format(dates, "%b")
summary <- paste(labels, collapse = ",")
cat(summary, "\n", sep = "")
start <- as.Date("2026-01-01")
month_step <- 3
dates <- seq.Date(start, by = paste(month_step, "month"), length.out = 4)
labels <- format(dates, "%b")
summary <- paste(labels, collapse = ",")
cat(summary, "\n", sep = "")
start ← 2026-01-01
1start <- as.Date("2026-01-01")2month_step <- 1values this step2026-01-01startmonth_step ← 1
1start <- as.Date("2026-01-01")2month_step <- 13dates <- seq.Date(start, by = paste(month_step, "month"), length.out = 4)values this step1month_stepdates ← 2026-01-01, 2026-02-01, 2026-03-01, 2026-04-01
2month_step <- 13dates <- seq.Date(start, by = paste(month_step, "month"), length.out = 4)4labels <- format(dates, "%b")values this step2026-01-01, 2026-02-01, 2026-03-01, 2026-04-01dates2026-01-01start1month_steplabels ← Jan, Feb, Mar, Apr
3dates <- seq.Date(start, by = paste(month_step, "month"), length.out = 4)4labels <- format(dates, "%b")5summary <- paste(labels, collapse = ",")values this stepJan, Feb, Mar, Aprlabels4 monthly datesdatessummary ← Jan,Feb,Mar,Apr
4labels <- format(dates, "%b")5summary <- paste(labels, collapse = ",")6cat(summary, "\n", sep = "")values this stepJan,Feb,Mar,AprsummaryJan, Feb, Mar, Aprlabelscat(summary, " ", sep = "")
5summary <- paste(labels, collapse = ",")6cat(summary, "\n", sep = "")outputJan,Feb,Mar,Aprvalues this stepJan,Feb,Mar,Aprsummary
start ← 2026-01-01
1start <- as.Date("2026-01-01")2month_step <- 2values this step2026-01-01startmonth_step ← 2
1start <- as.Date("2026-01-01")2month_step <- 23dates <- seq.Date(start, by = paste(month_step, "month"), length.out = 4)values this step2month_stepdates ← 2026-01-01, 2026-03-01, 2026-05-01, 2026-07-01
2month_step <- 23dates <- seq.Date(start, by = paste(month_step, "month"), length.out = 4)4labels <- format(dates, "%b")values this step2026-01-01, 2026-03-01, 2026-05-01, 2026-07-01dates2026-01-01start2month_steplabels ← Jan, Mar, May, Jul
3dates <- seq.Date(start, by = paste(month_step, "month"), length.out = 4)4labels <- format(dates, "%b")5summary <- paste(labels, collapse = ",")values this stepJan, Mar, May, Jullabels4 two-month datesdatessummary ← Jan,Mar,May,Jul
4labels <- format(dates, "%b")5summary <- paste(labels, collapse = ",")6cat(summary, "\n", sep = "")values this stepJan,Mar,May,JulsummaryJan, Mar, May, Jullabelscat(summary, " ", sep = "")
5summary <- paste(labels, collapse = ",")6cat(summary, "\n", sep = "")outputJan,Mar,May,Julvalues this stepJan,Mar,May,Julsummary
start ← 2026-01-01
1start <- as.Date("2026-01-01")2month_step <- 3values this step2026-01-01startmonth_step ← 3
1start <- as.Date("2026-01-01")2month_step <- 33dates <- seq.Date(start, by = paste(month_step, "month"), length.out = 4)values this step3month_stepdates ← 2026-01-01, 2026-04-01, 2026-07-01, 2026-10-01
2month_step <- 33dates <- seq.Date(start, by = paste(month_step, "month"), length.out = 4)4labels <- format(dates, "%b")values this step2026-01-01, 2026-04-01, 2026-07-01, 2026-10-01dates2026-01-01start3month_steplabels ← Jan, Apr, Jul, Oct
3dates <- seq.Date(start, by = paste(month_step, "month"), length.out = 4)4labels <- format(dates, "%b")5summary <- paste(labels, collapse = ",")values this stepJan, Apr, Jul, Octlabels4 quarterly datesdatessummary ← Jan,Apr,Jul,Oct
4labels <- format(dates, "%b")5summary <- paste(labels, collapse = ",")6cat(summary, "\n", sep = "")values this stepJan,Apr,Jul,OctsummaryJan, Apr, Jul, Octlabelscat(summary, " ", sep = "")
5summary <- paste(labels, collapse = ",")6cat(summary, "\n", sep = "")outputJan,Apr,Jul,Octvalues this stepJan,Apr,Jul,Octsummary
seq.Date
`seq.Date(start, by = ..., length.out = ...)` builds regular date sequences.
month step
`paste(month_step, "month")` creates a step such as `2 month`.
format
`format(dates, "%b")` converts dates into month labels.