Week 1 · Advanced Statistical Programming using R
You open your terminal and want to know where you are in the file system. Which command do you run?
lscdpwdmkdirAnswer: c) pwd — print working directory, displays your current location in the file system.
You are in /Users/john/Documents/Research/DataVis. Which command takes you directly to your home directory?
cd /cd ..cd ~cd homeAnswer: c) cd ~ — ~ is shorthand for the user’s home directory, regardless of where you currently are.
You are in Documents/Research/DataVis and want to navigate up two levels to Documents in one step. Which command achieves this?
cd ..cd ../..cd ../../Documentscd ~Answer: b) cd ../.. — each .. moves up one level; chaining them with / navigates multiple levels in one command.
Which command lists all files in a directory, including hidden ones?
lsls -rls -apwd -aAnswer: c) ls -a — the -a flag includes hidden files (those whose names start with .).
What is the correct order of Git commands to record a change to analysis.R in the version history?
git commit -m "update" → git add analysis.Rgit add analysis.R → git commit -m "update"git init → git add analysis.Rgit add analysis.R → git pushAnswer: b) — git add stages the change; git commit then records the snapshot in the version history.
You want to copy a folder called data/ and all its contents to a new location. Which command is correct?
cp data/ newlocation/mv data/ newlocation/cp -r data/ newlocation/rm -r data/ newlocation/Answer: c) cp -r data/ newlocation/ — the -r (recursive) flag is required to copy a directory and all its contents.
Which dplyr function would you use to keep only rows where country == "Germany"?
select(country == "Germany")filter(country == "Germany")mutate(country == "Germany")arrange(country == "Germany")Answer: b) filter() — filter() subsets rows based on a condition. select() picks columns, mutate() adds/modifies columns, arrange() reorders rows.
You want to compute the mean income separately for each region. Which code is correct?
df |> summarise(mean(income))df |> group_by(income) |> summarise(mean(region))df |> group_by(region) |> summarise(mean_income = mean(income, na.rm = TRUE))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.
What does pivot_longer() do?
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.
What does the aes() function do in a ggplot2 call?
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.