Welcome to this tutorial on Data Handling in R! In this tutorial, you will learn the basics of managing and handling data in R through a series of four exercises:
Each exercise is provided as a separate document. By the end of this tutorial, you should be confident in using the RStudio interface, handling data, performing transformations, creating visualizations, and producing reproducible reports with R Markdown.
There is some prerequisite knowledge that you should know before starting this tutorial, including: - Basic programming concepts: loops, conditionals and functions. - Basic knowledge of data structures in R: data frames, vectors. - Basic knowledge of data types: numeric, integer, logical/boolean, character/string, list. - Basic knowledge of descriptive statistics: mean, median, standard deviation, variance.
Before we get started on the exercises, we need to ensure that everything is installed.
To install R:
To install RStudio:
It is important to regularly update R and RStudio to ensure that you have the latest versions installed and avoid errors.
You might be wondering what the difference is between R and RStudio.
R is a programming language and software environment widely used for statistical analysis, data manipulation, and visualization.
RStudio is an Integrated Development Environment (IDE) for R, containing a set of tools built to make R easier to use and provide additional functionality. RStudio combines a source code editor, build automation tools, and a debugger. RStudio is what we’ll be using to write our code.
In this tutorial, we will use a modified version of the Scottish Health Survey (SHeS) dataset which we provide on the MANTRA website. SHeS is an open-source dataset by the Scottish government that provides indicators of population health and related risk factors. More details are available on the Scottish Government website.
Scottish Government. (2022). Scottish Health Survey-Scotland level data: Indicators of population health and related risk factors from the Scottish Health Survey (2008-2022) [Data set]. statistics.gov.scot. https://statistics.gov.scot/data/scottish-health-survey-scotland-level-data