• Stars
    star
    705
  • Rank 58,599 (Top 2 %)
  • Language
    R
  • License
    GNU General Publi...
  • Created over 14 years ago
  • Updated 7 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Make working with dates in R just that little bit easier

lubridate

CRAN version R build status Coverage Status CRAN RStudio mirror downloads Development version

Overview

Date-time data can be frustrating to work with in R. R commands for date-times are generally unintuitive and change depending on the type of date-time object being used. Moreover, the methods we use with date-times must be robust to time zones, leap days, daylight savings times, and other time related quirks, and R lacks these capabilities in some situations. Lubridate makes it easier to do the things R does with date-times and possible to do the things R does not.

If you are new to lubridate, the best place to start is the date and times chapter in R for data science.

Installation

# The easiest way to get lubridate is to install the whole tidyverse:
install.packages("tidyverse")

# Alternatively, install just lubridate:
install.packages("lubridate")

# Or the the development version from GitHub:
# install.packages("devtools")
devtools::install_github("tidyverse/lubridate")

Cheatsheet

Features

library(lubridate, warn.conflicts = FALSE)
  • Easy and fast parsing of date-times: ymd(), ymd_hms, dmy(), dmy_hms, mdy(), …

    ymd(20101215)
    #> [1] "2010-12-15"
    mdy("4/1/17")
    #> [1] "2017-04-01"
  • Simple functions to get and set components of a date-time, such as year(), month(), mday(), hour(), minute() and second():

    bday <- dmy("14/10/1979")
    month(bday)
    #> [1] 10
    wday(bday, label = TRUE)
    #> [1] Sun
    #> Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat
    
    year(bday) <- 2016
    wday(bday, label = TRUE)
    #> [1] Fri
    #> Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat
  • Helper functions for handling time zones: with_tz(), force_tz()

    time <- ymd_hms("2010-12-13 15:30:30")
    time
    #> [1] "2010-12-13 15:30:30 UTC"
    
    # Changes printing
    with_tz(time, "America/Chicago")
    #> [1] "2010-12-13 09:30:30 CST"
    
    # Changes time
    force_tz(time, "America/Chicago")
    #> [1] "2010-12-13 15:30:30 CST"

Lubridate also expands the type of mathematical operations that can be performed with date-time objects. It introduces three new time span classes borrowed from https://www.joda.org.

  • durations, which measure the exact amount of time between two points

  • periods, which accurately track clock times despite leap years, leap seconds, and day light savings time

  • intervals, a protean summary of the time information between two points

Code of Conduct

Please note that the lubridate project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

More Repositories

1

ggplot2

An implementation of the Grammar of Graphics in R
R
6,163
star
2

dplyr

dplyr: A grammar of data manipulation
R
4,556
star
3

tidyverse

Easily install and load packages from the tidyverse
R
1,480
star
4

rvest

Simple web scraping for R
R
1,428
star
5

tidyr

Tidy Messy Data
R
1,298
star
6

purrr

A functional programming toolkit for R
R
1,185
star
7

readr

Read flat files (csv, tsv, fwf) into R
R
971
star
8

magrittr

Improve the readability of R code with the pipe
R
942
star
9

datascience-box

Data Science Course in a Box
JavaScript
852
star
10

reprex

Render bits of R code for sharing, e.g., on GitHub or StackOverflow.
R
716
star
11

readxl

Read excel files (.xls and .xlsx) into R πŸ–‡
C++
699
star
12

dtplyr

Data table backend for dplyr
R
639
star
13

multidplyr

A dplyr backend that partitions a data frame over multiple processes
R
632
star
14

tibble

A modern re-imagining of the data frame
R
623
star
15

vroom

Fast reading of delimited files
C++
589
star
16

stringr

A fresh approach to string manipulation in R
R
555
star
17

forcats

🐈🐈🐈🐈: tools for working with categorical variables (factors)
R
522
star
18

dbplyr

Database (DBI) backend for dplyr
R
416
star
19

haven

Read SPSS, Stata and SAS files from R
C
414
star
20

modelr

Helper functions for modelling
R
398
star
21

googlesheets4

Google Spreadsheets R API (reboot of the googlesheets package)
R
330
star
22

googledrive

Google Drive R API
R
297
star
23

style

The tidyverse style guide for R code
HTML
275
star
24

design

Tidyverse design principles
R
203
star
25

tidyverse.org

Source of tidyverse.org
HTML
172
star
26

hms

A simple class for storing time-of-day values
R
134
star
27

nycflights13

An R data package containing all out-bound flights from NYC in 2013 + useful metdata
R
116
star
28

tidyversedashboard

Tidyverse activity dashboard
R
69
star
29

tidy-dev-day

Tidyverse developer day
57
star
30

tidyeval

A guide to tidy evaluation
CSS
51
star
31

dsbox

Companion R package to Data Science Course in a Box
R
44
star
32

blob

A simple S3 class for representing BLOBs
R
42
star
33

tidytemplate

A pkgdown template for core tidyverse packages
SCSS
42
star
34

funs

Collection of low-level functions for working with vctrs
R
30
star
35

website-analytics

Web analytics for tidyverse + r-lib sites
R
27
star
36

code-review

23
star
37

tidyups

19
star
38

ggplot2-docs

ggplot2 documentation. Auto-generated from ggplot2 sources by pkgdown
HTML
9
star