knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(reproseries) library(magrittr)
The reproseries
package itself is not sufficient, we need magrittr
to pipe functions together.
This vignette shows what you can do with the functions in the reproseries
package. Code is not hidden so you can follow along nicely.
The functions are written to be used on the built-in nottem
dataset. This dataset looks like this:
temperatures <- nottem %>% temperatureSeriesToDf temperatures %>% str
We first transform nottem
from a time series in a dataframe object. This way str
gives us a clearer overview of what the dataset looks like.
The raw nottem
dataset is not tidy since variables are spread across columns. There are 3 variables (month, year and temperature) but there are 12 columns (one for each month). Let's fix this:
temperatures <- temperatures %>% tidyTemperatures temperatures %>% str
Now we have the 3 variables we need. Month and year are clear, value refers to the temperature in fahrenheit. In the next step we'll deal with this vague value
variable.
We're no Americans so transform fahrenheits to celsius.
temperatures <- temperatures %>% addCelsiusColumn temperatures %>% str
In preparation of the modeling and visualisation we already calculate an average temperature per year.
avg_temperature_by_year <- temperatures %>% summariseAvgTemperatureByYear avg_temperature_by_year %>% str
How did the average temperature evolve over the years?
avg_temperature_by_year %>%
plotAvgTemperaturesByYear
Is there a trend in the average temperatures?
avg_temperature_by_year %>%
calculateAutoCorrelation
0.10 is rather low so there doesn't seem to be any trend.
All the functions available in the reproseries
package have been introduced above.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.