R Programming Language Certification Data Manipulation & Tidyverse in R 1 — Questions and Answers
Question 1: Which tidyverse package is the primary tool for data manipulation in R?
- dplyr (Correct answer)
- tidyr
- purrr
- stringr
Correct answer: dplyr
dplyr provides a grammar of data manipulation with verbs like filter(), select(), mutate(), summarise(), and arrange().
Question 2: Which dplyr function selects a subset of rows based on a logical condition?
- filter() (Correct answer)
- select()
- slice()
- subset()
Correct answer: filter()
filter() keeps rows that satisfy one or more logical conditions, similar to WHERE in SQL.
Question 3: Which dplyr function adds new columns or transforms existing columns in a data frame?
- mutate() (Correct answer)
- transmute()
- add_column()
- transform()
Correct answer: mutate()
mutate() adds new variables or modifies existing ones while keeping all other columns in the data frame.
Question 4: What does the pipe operator |> (or %>%) do in R?
- Passes the left-hand result as the first argument to the right-hand function (Correct answer)
- Creates a logical OR condition
- Concatenates strings
- Combines two data frames
Correct answer: Passes the left-hand result as the first argument to the right-hand function
The pipe |> (native R 4.1+) or %>% (magrittr) passes the left-hand expression as the first argument to the right-hand function, enabling chained operations.
Question 5: Which dplyr function calculates summary statistics for groups defined by one or more variables?
- summarise() after group_by() (Correct answer)
- aggregate()
- tapply()
- collapse()
Correct answer: summarise() after group_by()
group_by() followed by summarise() computes summary statistics (like mean, sum, count) for each group.
Question 6: Which dplyr function reorders rows by one or more columns?
- arrange() (Correct answer)
- order()
- sort()
- rank()
Correct answer: arrange()
arrange() sorts rows by specified columns in ascending order (or descending with desc()).
Which tidyverse package is the primary tool for data manipulation in R?