Time | Content |
---|---|
10:00โ10:30 | Getting Started |
10:30โ10:45 | Exercise 1 |
10:45โ11:15 | Working with objects |
11:15โ11:30 | Exercise 2 |
11:30โ11:40 | Break |
11:40โ12:00 | Reading and writing data |
12:00โ12:10 | Exercise 3 |
12:10โ12:40 | Functions, loops and conditional statements |
12:40โ12:50 | Exercise 4 |
12:50โ13:00 | Wrap-up |
Materials
๐ Schedule
๐ Resources
๐๏ธโโ๏ธ Exercises
Get to know fellow workshop participants
- Introduce yourself to those on your table.
- Ask what their favorite number is and record this.
- Using R, calculate the mean and standard deviation of the favorite numbers of all the participants on your table.
Using R as a calculator
Using R either on your laptop or above console, compute the following values and write the answer in the box.
- What is \((40 + 5) \times 3\)?
- What is \(\sqrt{2^4 - 7}\)?
- What is \(\dfrac{e^2 + 1}{2}\) to two decimal places?
- What is \(\log_2(9)\) to two decimal places?
Finding new functions
The following operations were not shown in the slides so you will need to find the relevant functions yourself. How would you find these? Once you find the relevant functions, compute the following values in R and enter the value in the corresponding box.
- What is \(10! = 10\times 9 \times 8 \times \cdots \times 2 \times 1\)? This operation is referred to as โfactorialโ.
- What is \(\cos\left(\frac{2}{3}\pi\right) + \sin(-\pi)\) to two decimal places?
- The \(\lfloor x \rfloor\) denotes the floor function (the largest integer such that it is smaller or equal to \(x\)) and \(\lceil x \rceil\) denotes the ceiling function (the smallest integer such that it is larger or equal to \(x\)). What is \(\lfloor \frac{1}{4} \pi \rfloor + \lceil \pi e \rceil\)?
Installing R packages
- Which function installs an R package from CRAN?
- Which function loads an R package into your system?
- On your own laptop, install the following packages:
praise
,readr
,readxl
,reprex
,sessioninfo
.
- What function is in the
praise
package? Try running this function on your own laptop.
- Conduct elementary arithmetic operations using R
- Navigate the RStudio interactive development environment (IDE)
- Install external packages in R to extend functionality
Using R either on your laptop or above console, compute the following values and enter your answer in the corresponding box.
Object class
R has a number of built-in datasets (see data(package = "datasets")
).
Identify the object class for the following variables:
Dataset | Variable | Class |
---|---|---|
PlantGrowth |
weight |
|
PlantGrowth |
group |
|
infert |
education |
|
infert |
age |
|
infert |
case |
|
Harman23.cor |
cov |
|
Harman23.cor |
center |
|
Harman23.cor |
n.obs |
Compute summary statistics
- What is the median weight of plants in the control group in
PlantGrowth
data? - What is the total number of cases (
case = 1
) in infertility after spontaneous and induced abortion in theinfert
data? - What is the 20th value in the
education
variable ininfert
data? - What is the value in the fifth row, fifth column in the
cov
matrix inHarman23.cor
data? - What is the mean ozone value in
airquality
data to two decimal places? - What is the number of missing values in solar radiation values in
airquality
data? Hint: what doesis.na()
do?
- Comprehend various object types in R
- Manipulate lists, matrices, and vectors in R
- Compute basic summary statistics including mean, median, quartiles, and standard deviation using R
- Grasp the concept of missing values within the R environment
Download the data
Download the above datasets.
- Read the data in
roadside-transects.csv
. How many variables does this sheet consist of? How many observations are there? - Read the sheet โValues for RWC figuresโ in
branch-water-derived-value.xlsx
. How many variables does this sheet consist of? How many observations are there? - Read the sheet โKey Valuesโ in
branch-water-derived-value.xlsx
. How many variables does this sheet consist of? How many observations are there?
For more practice, see here for more datasets to try reading into R.
- Import and export data in R
Using R either on your laptop or the consoles below, compute the following values and enter your answer in the corresponding box.
cor.test()
is a function that test for association between paired samples. E.g.cor.test(mtcars$mpg, mtcars$disp)
tests the association for the two variablesmpg
(miles per gallon) anddisp
(displacement) in themtcars
dataset. The \(p\)-value of the test can be accessed bycor.test(mtcars$mpg, mtcars$disp)$p.value
. What is the \(p\)-value of the test of association for thespeed
anddist
variables in thecars
dataset?
- Write a function that computes the number of distinct values in a vector. Use this to find the number of distinct values in
mtcars$vs
. What is the result?
- Compute a pairwise correlation test for all pair of variables in
mtcars
dataset if the number of distinct values are greater than 3.
Which pair of variables has the highest \(p\)-value? (Enter it alphabetical order) var1
: and var2
:
- Create basic functions, employ conditional statements, and utilize for loops in R
- Decipher error messages and do basic troubleshooting