CHAPTER 5

image

Working with Dates and Strings

In Chapter 5, you will learn how to work with dates and strings.

Recipe 5-1. Working with Dates and Times

Problem

When you import date and time data into R, these are not recognized automatically. To work with them, you must convert dates and times to the proper format.

Solution

The system’s idea of the current date is returned by the Sys.Date() function. You can retrieve the current date with the time by using the Sys.time() function. Examine the following examples.

> Sys.time()[1] "2014-06-03 13:26:35.06454 EDT"> ## locale-specific version of date()> format(Sys.time(), "%a %b %d %X %Y")[1] "Tue Jun 03 ...

Get R Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.