Skip to content

Commit

Permalink
Minor date-time tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Apr 22, 2016
1 parent ac6c767 commit d43119a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions datetimes.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 4,7 @@ This chapter will show you how to work with dates and times in R. Dates and time

This chapter will focus on R's __lubridate__ package, which makes it much easier to work with dates and times in R. You'll learn the basic date time structures in R and the lubridate functions that make working with them easy. We will also rely on some of the packages that you already know how to use, so load this entire set of packages to begin:

```{r messages = FALSE, warnings = FALSE}
```{r message = FALSE, warning = FALSE}
library(nycflights13)
library(dplyr)
library(stringr)
Expand All @@ -14,7 14,7 @@ library(lubridate)

## Parsing times

Time data normally comes as character strings, or numbers spread across columns, as in the `flights` data set from Chapter ?.
Time data normally comes as character strings, or numbers spread across columns, as in the `flights` data set from [Relational data].

```{r}
flights %>%
Expand Down Expand Up @@ -114,7 114,6 @@ zero_day - 1

R can also save datetimes in the POSIXlt form, a list based date structure. Working with POSIXlt dates can be much slower than working with POSIXct dates, and I don't recommend it. Lubridate's parse functions will always return a POSIXct date when you supply an hour, minutes, or seconds component.


## Arithmetic with dates

Did you see how I calculated the scheduled departure and arrival times for our flights? I added the appropriate number of seconds to the actual departure and arrival times. You can take this approach even farther by adding hours, days, weeks, and more.
Expand Down Expand Up @@ -384,7 383,7 @@ datetimes %>%
geom_bar(stat = "identity")
```

You cn also use the `yday()` accessor to see that average delays fluctuate throughout the year.
You can also use the `yday()` accessor to see that average delays fluctuate throughout the year.

```{r fig.height=3, warning = FALSE}
datetimes %>%
Expand All @@ -397,7 396,6 @@ datetimes %>%
```



### Setting dates

You can also use each accessor funtion to set the components of a date or datetime.
Expand Down
2 changes: 1 addition & 1 deletion relational-data.Rmd
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
# Relational data {#relation-data}
# Relational data

```{r setup-relation, include = FALSE}
library(dplyr)
Expand Down

0 comments on commit d43119a

Please sign in to comment.