Intermediate R test (Intermediate)
30 questions · 35 minutes · Free
dplyr, tidyr, ggplot2 and functions.
What it covers
- dplyr
- tidyr
- ggplot2
- Writing functions
- apply family
Interview format
- Questions: 30 questions — 18 multiple choice, 9 multi-answer, 3 predict-the-output
- Time: 35 minutes, timed from the first question
- Difficulty: Intermediate
- Skill area: Data
- Price: Free
Sample questions
5 sample questions from the Intermediate R test, with the answers. Samples are taken out of the live test, so you will not meet these when you sit it.
What is the primary purpose of using the ellipsis (`...`) in R functions?
- It is used to define default values for function parameters.
- It is used to ignore unused arguments in a function.
- It allows a function to accept a variable number of arguments, which can be accessed as a list within the function.
- It is used to return multiple values from a function.
Answer: C. It allows a function to accept a variable number of arguments, which can be accessed as a list within the function.
In R, the ellipsis (`...`) is used to pass a variable number of arguments to a function. These arguments are collected into a list and can be accessed within the function using `list(...)`. This is particularly useful for functions that need to handle a flexible number of inputs, such as `plot()` or `ggplot()`. The other options describe incorrect or incomplete behaviors of the ellipsis.
Which ggplot2 function is appropriate for creating a grid of plots with rows and columns defined by variables, and how does it compare to an alternative for a single variable with many levels?
- facet_grid(rows ~ cols)
- facet_grid(cols ~ rows)
- facet_grid(~ var)
- facet_wrap(~ var)
Answer: A. facet_grid(rows ~ cols)
facet_grid(rows ~ cols) is used to create a grid of plots with rows and columns defined by variables. It is appropriate when you want to split the data into a two-dimensional grid based on two variables. In contrast, facet_wrap(~ var) is used to wrap a single variable into a one-dimensional layout, which is suitable for a single variable with many levels. The question asks specifically about facet_grid with rows and columns, making facet_grid(rows ~ cols) the correct answer.
Which of the following statements best describes the purpose of the `expand()` function in the `tidyr` package?
- The `expand()` function from the `tidyr` package is used to filter out rows that contain missing values.
- The `expand()` function from the `tidyr` package is used to gather multiple columns into a single column, creating a long format dataset.
- The `expand()` function from the `tidyr` package is used to replace missing values with a specified value, such as zero.
- The `expand()` function from the `tidyr` package is used to generate all possible combinations of values from specified columns, creating a grid of combinations.
Answer: D. The `expand()` function from the `tidyr` package is used to generate all possible combinations of values from specified columns, creating a grid of combinations.
The `expand()` function in `tidyr` is designed to create a grid of all combinations of values from specified columns, which is particularly useful when you want to generate complete data frames with missing combinations of values. This is a common use case for `expand()`, especially when working with data that has implicit missing values.
In a ggplot2 visualization, you need to limit the y-axis to values between 0 and 100. Which of the following options is the correct way to apply this using `scale_y_continuous`?
- scale_y_continuous(limits = c(0, 100))
- scale_y_continuous(limit = c(0, 100))
- scale_y_continuous(range = c(0, 100))
- scale_y_continuous(lim = c(0, 100))
Answer: A. scale_y_continuous(limits = c(0, 100))
The `scale_y_continuous(limits = c(0, 100))` function correctly sets the y-axis limits to range from 0 to 100. The other options either use incorrect function names, parameters, or formatting.
Which of the following statements accurately describes the behavior of an inner join and a left join in dplyr?
- An inner join returns all rows from both tables, while a left join returns only the rows that have matching values in both tables.
- A left join returns all rows from both tables, while an inner join returns only the rows that have matching values in both tables.
- An inner join returns only the rows that have matching values in both tables, while a left join returns all rows from the left table and matching rows from the right table, filling in NA for unmatched rows.
- A left join returns only the rows that have matching values in both tables, while an inner join returns all rows from the left table and matching rows from the right table, filling in NA for unmatched rows.
Answer: C. An inner join returns only the rows that have matching values in both tables, while a left join returns all rows from the left table and matching rows from the right table, filling in NA for unmatched rows.
An inner join returns only the rows that have matching values in both tables, while a left join returns all rows from the left table and matching rows from the right table, filling in NA for unmatched rows.
Frequently asked questions
- How many questions are in the Intermediate R test?
- 30 questions (18 multiple choice, 9 multi-answer, 3 predict-the-output), with 35 minutes to answer them.
- What does the Intermediate R test cover?
- dplyr, tidyr, ggplot2, Writing functions, apply family.
- Is the Intermediate R test free?
- Yes. It is free to take with a readyforhires account.
- What level is the Intermediate R test?
- Intermediate, in Data.