Ad space (banner)
๐Ÿ“ŠR Lessons
Lesson 36 / 68

Assembling and displaying a date

This lesson covers handling dates in R, with the aim of assembling a date and finding its day of the week.

as.Date() builds date data from a string. Getting the day of the week and changing the display format are both straightforward with format().

The sample code builds a date with as.Date("2026-08-09") and converts it to a display format with format(d, "%m/%d/%Y"). Note how format(d, "%w") gets the weekday number and combines it with an array of weekday names.

A common early stumble is the format string itself. Specifiers such as %Y, %m, and %d each change the output, so you have to look up the one that suits your purpose.

In professional work, dates come up constantly in data analysis — time-series work, report generation.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run R directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)