Summary and Schedule
This is an introduction to R and RStudio designed for music researchers with no programming experience. The lesson aims to showcase how an individual might find R useful for their music research. Some initial information about the R syntax and navigating the RStudio interface are given, followed by information about how to import CSV files, clean your data, look at subsets of your data, carry out some initial statistical calculations, visualising different elements of your data, and finally, present some best practices when writing code in R.
Two example case studies are used in this lesson, featuring two types of web data sets - by no means does this lesson present an exhaustive list of the uses of R. The case studies presented are two of several potential use cases of how an individual may use R for their research and to work with data.
The main aim is to give a taste of what R can do for music researchers, and hopefully encourage researchers to consider R as one of multiple useful tools in their tool kit when it comes to working with data for their music research.
Prerequisite
- This lesson requires R and RStudio to be installed on the learner’s device.
- The two dummy data set files need to be downloaded in preparation for this lesson.
Setup Instructions | Download files required for the lesson | |
Duration: 00h 00m | 1. R for Music Research | Why should I use R in my music research? |
Duration: 00h 00m | 2. Meet Alex | |
Duration: 00h 05m | 3. Getting started with R and RStudio |
How do I navigate the RStudio user interface? How do I run commands in the console? What is an R script and how do I create one? What are library packages? How do I get help? |
Duration: 00h 40m | 4. Creating a directory structure |
What is a working directory? How do I set up a new working directory? How do I create new directories? How do I check what files are in my directory? |
Duration: 00h 40m | 5. Reading survey data in R |
How do I import csv and Excel data files in R? How can R deal with missing values on import? How do I give names to the data set imported? :::::::::::::::::::::::::::::::::::::::::::::::: |
Duration: 00h 40m | 6. Inspecting your data in R |
How many rows and columns are in my data frame? What are the names of the columns in my data frame? How can I look up parts of my data frame? How do I find out what the internal structure of my data frame is? |
Duration: 00h 40m | 7. Cleaning your data |
What are some steps I should take to clean my data before use? How do I identify and deal with missing values in the data? How do I save my cleaned data into a new data file? |
Duration: 00h 40m | 8. Analysing survey data |
What are some descriptive statistics of my data set that I can compute
in R? How do I calculate the number of participants in my survey data? How do I calculate the mean age of participants in my survey data? How do I found out what age are the youngest and oldest participants in my survey data? How do I compare scores of participants based on their musicianship? How do I carry out a t-test? |
Duration: 00h 40m | 9. Visualising survey data with ggplot2 |
What are the 3 main components of a ggplot? How do I create a scatterplot, boxplot, and a bar graph to visualise my data? How can I create separate plots at once based on a variable of my data? How do I customise my plots to add axes labels and a title? How do I save my plots in png format? |
Duration: 00h 40m | 10. A second case study for music research |
Can I apply what I learnt about R for a different case study? How do I read data from an online dataset in R? How can I look up specific parts of the dataset? How can I visualise specific parts of the dataset? |
Duration: 00h 40m | 11. Some best practices when writing code in R | What are some best practices to keep in mind when writing code in R? |
Duration: 00h 40m | Finish |
The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.
Software Setup
R and RStudio Setup Instructions
First, download and install R, and then download and install RStudio. Setup may vary slightly across systems. Different setup instructions based on whether your system is Windows, MacOS, or Linux may be access via the dropdown menus below.
- Download R from the CRAN website
- Run the .exe file that was just downloaded.
- Go to the RStudio download page.
- Press on the ‘Download RStudio’ button. This will direct you to the installation set up with 2 steps.
- Step 1 is installing R which you will have already done, so skip that and go to Step 2.
- Scroll down the web page to the Installers tab and download the Windows version of RStudio.
- Double click the file to install it.
- Once installed, try opening RStudio Desktop to check that it works.
- Go to the CRAN website and select the .pkg file for the latest R version, based on your Mac’s processor.
- Please note that there are two different packages depending on if your Mac has an Apple silicon processor (M1/M2 chip) or works with an Intel processor.
- You can check your Mac’s processor type by clicking on the Apple icon at the upper left corner and clicking on About This Mac.
- Download the relevant .pkg file and double click to install it.
- Go to the RStudio download page.
- Press on the ‘Download RStudio’ button. This will direct you to the installation set up with 2 steps.
- Step 1 is installing R which you will have already done, so skip that and go to Step 2.
- Scroll down the web page to the Installers tab and download the latest RStudio version for Mac.
- Double click the file to install it.
- Once installed, try opening RStudio Desktop to check that it works.
- Go to the CRAN website and follow the instructions for your distribution to download and install R.
- After R is installed, go to the RStudio download page.
- Under Installers select the version that matches your distribution, and install it with your preferred method.
- Once installed, open RStudio to make sure it works.
The RStudio environment is what we will be working in during this lesson.
Data Sets
Download the data-files folder and put it on your Desktop.