Tutorial 1
Installing R
First, you need to download and install the latest version of R.
- Go to R official website
- Click on “download R”
- Save the installation file
- Run the installation file and follow the prompts to install R (default settings are fine)
Installing RStudio
- Go to RStudio
- Click the big blue download button to download the installation file
- Run the installation file and follow the prompts to install RStudio (default settings are fine)
Cheatsheets
If you forget how to use it or are not sure, there are some cheatsheets for you: RStudio cheatsheet
Question set 1 – Getting started
- Q1: Create a new R script
tutorial1.R
- Q2: Execute the following code
- Q3: Use RStudio tab panes to explore
fakedata
- Q4: Explain the functions
mean()
andsd()
- Q5: If we calculate
mean(fakedata)
, it will result in an error. Why does this happen, and how should we fix the error?
Question set 2 – Data types
Q1: We have 25 students in BIOF1001, to store the final marks (0 to 100 with a precision of 0.1), what data type will we use?
Q2: For the grades (
A+
toF
), what data type and data structure can be used to keep the data?Q3: If you have two vectors for the BIOF1001
marks
andgrades
and onecharacter
for teaching performance"good"
, and you want to store them into one variable, which data structure will you use?
Question set 3 – Matrix manipulation
- Q1: Make a matrix named
my_matrix
with a shape of 5 rows and 2 columns, filled with values from 3 to 12, where the first row contains 3 and 4. Hint: For creating a vector from 3 to 12, you may useseq()
or:
.
- Q2: Based on
Q1
, add the row names toDay1
toDay5
and column names toLunch
andDinner
.
- Q3: Based on
Q2
, extract a matrix with a shape of 3x1 containing the values 6, 8, and 10 from the matrixmy_matrix
.
- Q4: What will you get for
my_matrix[c(TRUE, FALSE, FALSE, TRUE), ]
? Hint: think of recycling if the index length is different from the query dimension (Over-flexibility comes with a price of wrong use).
Question set 4 – Analyzing data
- Q1: Now, in your Desktop folder, create a subfolder named
R_exercises
and download this file of differentially expressed genes results Diff_Expression_results.tsv (or link to view) to the folder. Check your current working directory bygetwd()
function and change the working directory to the folder you just created. Hint: you may usesetwd()
to change the working directory or use theSession
button of RStudio.
- Q2: Related to Q1, use the
read.table()
function to load the file into a data frame with the variable namedf_DEG
. Hint: You may consider using the full path or just the file name if it’s in the same working directory. Please keepheader=TRUE
for the argument. Think how to find the help page for a certain function.
- Q3: Can you calculate the
mean
andstandard deviation
of thelog2FoldChange
?
Question set 5 – Scientific computing
- Q1: Write a function to solve a quadratic equation
\[ ax^2+bx+c=0 \]