Preamble
About the Author
Disclaimer
Foreword: Road Safety GB
Forword: Department for Transport
Forword: RAC Foundation
Preface
Thanks
1
Introduction
1.1
Reproducibility
1.2
What is R?
1.3
Why R for road safety research?
1.4
Prerequisites
1.5
Installing R and RStudio
1.6
R in the cloud
1.7
Recommended packages
1.8
Overview
2
R basics
2.1
Creating and removing R objects
2.2
Object types: vectors and data frames
2.3
Subsetting by index or column name
2.4
Subsetting by values
2.5
Dealing with NAs and recoding
2.6
Changing class
2.7
Recoding values
2.8
Saving R objects
2.9
Now you are ready to use RStudio
3
Using RStudio
3.1
Projects and scripts
3.2
Writing and running code
3.3
Viewing Objects
3.4
Autocompletion
3.5
Getting help
3.6
Commenting Code
3.7
The global environment
3.8
Debugging Code
3.9
Productivity boosting features
4
R packages
4.1
What are packages?
4.2
The stats19 R package
4.3
Installing packages
4.4
Loading packages
4.5
Using packages
4.6
Updating packages
4.7
ggplot2
4.8
dplyr
5
Manipulating data
5.1
tibbles
5.2
filter() and select() rows and columns
5.3
Ordering and selecting the ‘top n’
5.4
Summarise
5.5
Tidyverse exercises
6
Temporal data
6.1
Temporal analysis of crash data
6.2
Handling dates and date-times
6.3
Hours, minutes seconds with hms
6.4
The lubridate package
6.5
Dates in a data frame
6.6
Components of time objects
7
Spatial data
7.1
sf objects
7.2
Reading and writing spatial data
7.3
sf polygons
7.4
Spatial subsetting and sf plotting
7.5
Geographic joins
7.6
Coordinate Reference Systems
7.7
Buffers
7.8
Attribute operations on sf objects
7.9
Mapping road crash data
7.10
Analysing point data
7.11
Analysing crash data on road networks
Bonus exercises
8
Joining road crash tables
8.1
STATS19 tables
8.2
Joining casualty data
8.3
Joining vehicle data
8.4
Case study: London
9
Next steps
9.1
Automated reporting with RMarkdown
9.2
Sharing code
9.3
Asking questions
9.4
Testimonials
9.4.1
R for professional road safety analysts
9.4.2
R in a road safety research consultancy
9.4.3
Using R in a road safety charity
9.4.4
Using R in other areas of road safety research
10
References
11
rrsrr
Reproducible road safety research with R: A practical introduction
10
References