R Cheatsheet: Dates and Times

#R stores a date as the number of days counted from «Zero Day» which is January the first 1970. The same principle used by SAS, but the latter uses another «Start Date» or «Zero Day»

#Dates are represented as a «Date Class»

#On the other hand, times (number of seconds from «Start Date») are represented by any of the following classes:

#POSIXct (a single integer value representing the time)

#POSIXlt (a list of  values representing the time)

#Defining a Date:


#If we need to see the «value» of a particular date class we have to unclass it:


#So, it means it have passed 7329 since January 25th, 1990, the date stored in bday. Unclass is equivalent to the datepart() function of SAS.

#To obtain the current datetime, equals to TODAY() in SAS



#Of course we can use the POSIXlt to de-construct and obtain a singular value of our date.


#strptime is a useful function you can use to convert time in a POSIXlt or POSIXct format.

Etiquetas: , ,

About martincx

Fútbol, cine, historia y literatura. Quejándome del fútbol moderno. Bienvenido a mi morada. Entre libremente, por su propia voluntad, y deje parte de la felicidad que trae.

Este blog se enriquece con los comentarios, deja acá tu impresión.

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Salir /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Salir /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Salir /  Cambiar )

Conectando a %s

A %d blogueros les gusta esto: