Practice Session & Exercise

Introduction to R and Basic Programming Concepts

Author
Affiliation

Bioinformatics Core Facility CECAD

Published

September 23, 2026

1 Practice by Sessions

1.1 Session 2

1.1.1 Exercise 1:

Import the CSV file using readr from data/ directory.

Task: Read rna_results.csv into an object called results. Then print results.

1.1.2 Exercise 2:

Select only the following columns:

  • gene
  • log2FC
  • padj

1.1.3 Exercise 3:

Find genes that are:

  • significant: padj < 0.05
  • upregulated: log2FC > 0

Bonus question

How would you find significant downregulated genes?

1.1.4 Exercise 4:

Create a new column called direction.

The column should contain:

  • "Up" when log2FC > 0
  • "Down" when log2FC < 0

1.1.5 Exercise 5:

Create a new column called significant.

It should contain:

  • "Yes" when padj < 0.05
  • "No" otherwise.

1.1.6 Exercise 6:

Now combine both calculations.

Then keep only significant genes and display:

  • gene
  • log2FC
  • padj
  • direction

1.1.7 Exercise 7:

Arrange the results so that the genes with the smallest adjusted p-values appear first.

1.1.8 Exercise 8:

Arrange genes according to the absolute size of their log2 fold change, regardless of direction.

Which function can you use?

1.1.9 Exercise 9:

Calculate the mean log2FC among significant genes. Make use of summarise()

1.2 Exercise 10:

From the RNA-seq results, find significant genes, classify them as Up or Down, count how many genes are in each direction, and calculate the average log2FC for each direction.