Quiz: CLI, Git & Tidyverse

Week 1 · Advanced Statistical Programming using R

Git & Command Line

Q1

You open your terminal and want to know where you are in the file system. Which command do you run?

  1. ls
  2. cd
  3. pwd
  4. mkdir

Answer: c) pwd — print working directory, displays your current location in the file system.

Q2

You are in /Users/john/Documents/Research/DataVis. Which command takes you directly to your home directory?

  1. cd /
  2. cd ..
  3. cd ~
  4. cd home

Answer: c) cd ~~ is shorthand for the user’s home directory, regardless of where you currently are.

Q3

You are in Documents/Research/DataVis and want to navigate up two levels to Documents in one step. Which command achieves this?

  1. cd ..
  2. cd ../..
  3. cd ../../Documents
  4. cd ~

Answer: b) cd ../.. — each .. moves up one level; chaining them with / navigates multiple levels in one command.

Q4

Which command lists all files in a directory, including hidden ones?

  1. ls
  2. ls -r
  3. ls -a
  4. pwd -a

Answer: c) ls -a — the -a flag includes hidden files (those whose names start with .).

Q5

What is the correct order of Git commands to record a change to analysis.R in the version history?

  1. git commit -m "update"git add analysis.R
  2. git add analysis.Rgit commit -m "update"
  3. git initgit add analysis.R
  4. git add analysis.Rgit push

Answer: b)git add stages the change; git commit then records the snapshot in the version history.

Q6

You want to copy a folder called data/ and all its contents to a new location. Which command is correct?

  1. cp data/ newlocation/
  2. mv data/ newlocation/
  3. cp -r data/ newlocation/
  4. rm -r data/ newlocation/

Answer: c) cp -r data/ newlocation/ — the -r (recursive) flag is required to copy a directory and all its contents.

Tidyverse

Q7

Which dplyr function would you use to keep only rows where country == "Germany"?

  1. select(country == "Germany")
  2. filter(country == "Germany")
  3. mutate(country == "Germany")
  4. arrange(country == "Germany")

Answer: b) filter()filter() subsets rows based on a condition. select() picks columns, mutate() adds/modifies columns, arrange() reorders rows.

Q8

You want to compute the mean income separately for each region. Which code is correct?

  1. df |> summarise(mean(income))
  2. df |> group_by(income) |> summarise(mean(region))
  3. df |> group_by(region) |> summarise(mean_income = mean(income, na.rm = TRUE))
  4. df |> filter(region) |> mutate(mean_income = mean(income))

Answer: c)group_by() splits the data by region, then summarise() computes one value per group. na.rm = TRUE handles any missing values.

Q9

What does pivot_longer() do?

  1. Sorts rows from longest to shortest value
  2. Converts multiple columns into two columns: one for variable names, one for values
  3. Joins two data frames side by side
  4. Removes columns that contain long character strings

Answer: b)pivot_longer() reshapes wide data into long format, collapsing multiple columns into a name column and a value column. This is often needed before plotting with ggplot2.

Q10

What does the aes() function do in a ggplot2 call?

  1. Applies a colour palette to the plot
  2. Maps variables in the data to visual properties such as x, y, and colour
  3. Adds a geometric layer like points or bars
  4. Sets the plot title and axis labels

Answer: b)aes() (aesthetic mapping) connects columns in your data to visual properties of the plot. Without it, ggplot2 doesn’t know which variable goes on which axis.