Minor date-time tweaks

This commit is contained in:
hadley 2016-04-22 13:12:09 -05:00
parent ac6c767125
commit d43119af26
2 changed files with 4 additions and 6 deletions

View File

@ -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)
@ -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 %>%
@ -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.
@ -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 %>%
@ -397,7 +396,6 @@ datetimes %>%
```
### Setting dates
You can also use each accessor funtion to set the components of a date or datetime.

View File

@ -1,4 +1,4 @@
# Relational data {#relation-data}
# Relational data
```{r setup-relation, include = FALSE}
library(dplyr)