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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.