O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

Step 1 shows how to get the system date.

Steps 2 through 4 show how to create dates from strings. You can see that by specifying the format string appropriately, we can read dates from almost any string representation. We can use any separator as long as we mimic them in the format string. The following table summarizes the formatting options for the components of the date:

Format specifier

Description

%d

Day of month as a number, for example, 15

%m

Month as a number, for example, 10

%b

Abbreviated string representation of month, for example, Jan

%B

Complete string representation of month, for example, January

%y

Year as two digits, for example, 87

%Y

Year as four digits, for example, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required