Session 2
2024-02-06
By setting the working directory, you specify the location where RStudio will look for files and save outputs.
Using R:
This can be helpful for organizing your projects and ensuring that R scripts can access the necessary files.
To set the working directory in RStudio using the menu, follow these steps:
You’ll see the path to the chosen directory displayed in the Console panel at the bottom left corner of the RStudio interface or at the top right like in the image.
Let’s start with Exercises 1 and Exercise 2 !
It is Dr. John Snow’s famous map of the 1854 cholera outbreak in Soho, London. He drew and published to document the data collected during the epidemic. Each cross (bold lines stacked along the street) indicates a cholera-related death at that address. The article examines the true story behind the map but overall, it sheds light on the actual role of the map in understanding cholera transmission.
# import dataset.csv into object data
# [!] set the working directory first
data <- read.csv("data/dataset.csv")
# Describe the dataset
str(data)
# select a variable in a data frame
data$variable
# select values 2 to 5 in a variable
data$variable[2:5]
# select positive values
data$variable[ data$variable > 0]
Syntactic sugar: R pipes (see Irizarry ch. 4.5)
Execute / run selected code
Select multiple lines of code
Clear (erase) the Console
Insert <-
in your code
Insert %>%
in your code
Ctrl/Cmd-Enter
Shift + arrows
Ctrl-L
Alt-dash
(Alt + dash ʻ-ʼ key)
Ctrl/Cmd-Shift-M
Ctrl is for Windows and Mac, Cmd for Mac only