Datetimes behave nicely too
Just like Date
objects, you can plot and do math with POSIXct
objects.
As an example, in this exercise you'll see how quickly people download new versions of R, by examining the download logs from the RStudio CRAN mirror.
R 3.2.0 was released at "2015-04-16 07:13:33" so cran-logs_2015-04-17.csv
contains a random sample of downloads on the 16th, 17th and 18th.
This exercise is part of the course
Working with Dates and Times in R
Exercise instructions
- Use
read_csv()
to importcran-logs_2015-04-17.csv
. - Print
logs
to see the information we have on each download. - Store the R 3.2.0 release time as a
POSIXct
object. - Find out when the first request for 3.2.0 was made by filtering for values in the
datetime
column that are greater thanrelease_time
. - Finally see how downloads increase by creating histograms of download time for 3.2.0 and the previous version 3.1.3. We've provided most of the code, you just need to specify the
x
aesthetic to be thedatetime
column.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import "cran-logs_2015-04-17.csv" with read_csv()
logs <- read_csv(___)
# Print logs
___
# Store the release time as a POSIXct object
release_time <- ___("2015-04-16 07:13:33", tz = "UTC")
# When is the first download of 3.2.0?
logs %>%
filter(___,
r_version == "3.2.0")
# Examine histograms of downloads by version
ggplot(logs, aes(x = ___)) +
geom_histogram() +
geom_vline(aes(xintercept = as.numeric(release_time)))+
facet_wrap(~ r_version, ncol = 1)