Friday, May 13, 2016

R Language - Date and Time Related Commands

Working with dates in R

R has a range of functions that allow you to work with dates and times. The
easiest way of creating a date is to use the as.Date( ) function.

The default format for dates in as.Date( ) is YYYY-MM-DD
— four digits for year, and two digits for month and day, separated by a
hyphen.

To find out what day of the week this is, use weekdays():

You can add or subtract numbers from dates to create new dates.

use the seq( ) function to create sequences of dates in a far more
flexible way. As with numeric vectors, you have to specify at least three of the
arguments (from, to, by, and length.out).

In addition to weekdays( ), you also can get R to report on months() and
quarters( ):

Functions with Dates

Function
Description
as.Date()
Converts character string to Date
weekdays()
Full weekday name in the current locale (for example, Sunday, Monday, Tuesday)
months()
Full month name in the current locale (for example, January, February, March)
quarters()
Quarter numbers (Q1, Q2, Q3, or Q4)
seq()
Generates dates sequences if you pass it a Date object as its first argument


Objects that represent time series data.

ts: In R, you use the ts() function to create time series objects. These
are vector or matrix objects that contain information about the observations,
together with information about the start, frequency, and end of each
observation period. With ts class data you can use powerful R functions to do
modeling and forecasting — for example, arima() is a general model for time
series data.


Reference Book

R for Dummies, Vries and Meys
Chap 6

No comments:

Post a Comment