R Programming Language Certification Technology & Digital Applications 4 β Questions and Answers
Question 1: Which function in the `purrr` package applies a function to each element of a list and returns a list of results?
- map() (Correct answer)
- lapply()
- sapply()
- apply()
Correct answer: map()
`purrr::map()` applies a function to each element of a list or vector and always returns a list, providing consistent type behavior compared to base R equivalents.
Question 2: What is the purpose of `options(scipen = 999)` in R?
- Disables scientific notation for printing numbers (Correct answer)
- Sets the number of significant digits to 999
- Increases the penalty for using non-scientific functions
- Changes the locale for numeric formatting
Correct answer: Disables scientific notation for printing numbers
Setting `scipen` to a large positive value penalizes scientific notation display, causing R to print numbers in fixed-point notation instead.
Question 3: In R, which package provides the `%>%` pipe operator that passes the left-hand side as the first argument to the right-hand side function?
- magrittr (Correct answer)
- dplyr
- tidyr
- purrr
Correct answer: magrittr
The `%>%` pipe operator originates from the magrittr package, though it is re-exported by dplyr and other tidyverse packages for convenience.
Question 4: Which R function checks whether a package is installed and loads it, installing it first if necessary?
- pacman::p_load() (Correct answer)
- require()
- library()
- install.packages()
Correct answer: pacman::p_load()
`pacman::p_load()` checks if each listed package is installed, installs any that are missing, and then loads all of them in a single call.
Question 5: What does the `Rprof()` function do in R?
- Profiles R code execution to identify performance bottlenecks (Correct answer)
- Generates an R project configuration file
- Runs R scripts in a separate profiling environment
- Creates a profiling report in HTML format
Correct answer: Profiles R code execution to identify performance bottlenecks
`Rprof()` activates R's built-in profiler, recording function call stacks at regular intervals so you can identify which functions consume the most execution time.
Question 6: In R, which function converts a wide-format data frame to a long format by gathering multiple columns into key-value pairs?
- tidyr::pivot_longer()
- tidyr::gather()
- reshape2::melt()
- All of the above (Correct answer)
Correct answer: All of the above
All three functions convert wide data to long format: `pivot_longer()` is the modern tidyr approach, `gather()` is the older tidyr version, and `melt()` is the reshape2 equivalent.
Question 7: Which R package is used to interface with the Apache Arrow format for high-performance, cross-language data interchange?
- arrow (Correct answer)
- feather
- parquet
- arrowR
Correct answer: arrow
The `arrow` package provides bindings to the Apache Arrow C++ library, enabling fast reading/writing of Arrow, Parquet, and Feather formats in R.
Which function in the `purrr` package applies a function to each element of a list and returns a list of results?