R Functional Programming Basics Quiz

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Thames
T
Thames
Community Contributor
Quizzes Created: 6575 | Total Attempts: 67,424
| Questions: 15 | Updated: May 2, 2026
Please wait...
Question 1 / 16
🏆 Rank #--
0 %
0/100
Score 0/100

1. In R, what is a higher-order function?

Explanation

A higher-order function in R is defined by its ability to either accept another function as an argument or produce a function as a return value. This characteristic allows for more abstract and flexible programming, enabling the creation of functions that can operate on or generate other functions, enhancing code reusability and modularity.

Submit
Please wait...
About This Quiz
R Functional Programming Basics Quiz - Quiz

This R Functional Programming Basics Quiz assesses your understanding of core functional programming concepts in R, including higher-order functions, immutability, and functional composition. Designed for college students, it evaluates your ability to apply functional techniques like map, reduce, and filter operations. Master these foundational skills to write cleaner, more efficient... see moreR code. see less

2.

What first name or nickname would you like us to use?

You may optionally provide this to label your report, leaderboard, or certificate.

2. Which function in R applies a function to each element of a list or vector?

Explanation

In R, both `map()` and `lapply()` functions are designed to apply a function to each element of a list or vector. `map()` is part of the `purrr` package, while `lapply()` is a base R function. Therefore, both options b and c correctly identify functions that perform this operation.

Submit

3. What does the 'purrr' package's map() function return?

Explanation

The 'purrr' package's map() function is designed to apply a function to each element of a list or vector, returning the results as a new list. This allows for efficient and functional programming in R, making it easier to handle and manipulate collections of data.

Submit

4. In functional programming, immutability means that once a variable is assigned, it cannot be changed. True or False?

Explanation

Immutability in functional programming ensures that once a variable is assigned a value, it cannot be altered. This characteristic promotes safer and more predictable code by preventing unintended side effects, facilitating easier debugging and reasoning about program behavior, as data remains constant throughout its lifecycle.

Submit

5. Which R function reduces a list to a single value by applying a function cumulatively?

Explanation

The `reduce()` function in R is designed to apply a specified function cumulatively to the elements of a list, effectively reducing it to a single value. This is particularly useful for operations like summing or multiplying elements, where the result builds incrementally from the list's contents.

Submit

6. What is function composition in R?

Explanation

Function composition in R involves taking two or more functions and combining them to create a new function. This new function applies the first function's output as the input to the next function, allowing for streamlined and efficient processing of data through a sequence of operations.

Submit

7. The filter() function from 'purrr' returns elements that satisfy a ____.

Explanation

The filter() function in the 'purrr' package is designed to evaluate each element of a list or vector against a specified condition, known as a predicate. A predicate is a function that returns TRUE or FALSE, allowing filter() to retain only those elements that meet the criteria defined by the predicate.

Submit

8. In R, anonymous functions are often used in functional programming. Which syntax is correct for an anonymous function?

Explanation

In R, anonymous functions are defined using the `function` keyword followed by the parameters in parentheses. The expression follows the parameters, allowing for concise function creation without naming. The syntax `function(x) x + 1` correctly illustrates this, where `x` is the input and `x + 1` is the operation performed.

Submit

9. What does the Reduce() function do with the operation '+' on vector c(1, 2, 3, 4)?

Explanation

The Reduce() function applies the '+' operation cumulatively to the elements of the vector c(1, 2, 3, 4). It starts with the first two elements (1 + 2 = 3), then adds the next element (3 + 3 = 6), and finally adds the last element (6 + 4 = 10), resulting in a final output of 10.

Submit

10. A pure function always produces the same output for the same input and has no side effects. True or False?

Explanation

A pure function is defined by its consistency and lack of side effects. It guarantees that for any given input, the output will always be the same, ensuring predictability. Additionally, it does not alter any external state or variables, making it a fundamental concept in functional programming and enhancing code reliability and maintainability.

Submit

11. Which of the following is a characteristic of functional programming in R?

Explanation

Functional programming focuses on the application of functions and the use of expressions rather than statements. This paradigm emphasizes the "what" aspect—defining the desired outcome—over the "how" aspect, which involves the steps to achieve that outcome. This leads to clearer, more concise code that can be easier to reason about and maintain.

Submit

12. In R, the 'magrittr' pipe operator is represented as ____.

Explanation

In R, the 'magrittr' package introduces the pipe operator `%>%`, which allows for a more readable and efficient way to chain commands. This operator takes the output of one function and passes it as an input to the next function, enabling a streamlined workflow and enhancing code clarity.

Submit

13. What does sapply() do compared to lapply() in R?

Submit

14. Currying in functional programming refers to transforming a function with multiple arguments into a sequence of ____-argument functions.

Submit

15. The partial() function from 'purrr' allows you to fix some arguments of a function and create a new function. True or False?

Submit
×
Saved
Thank you for your feedback!
View My Results
Cancel
  • All
    All (15)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
In R, what is a higher-order function?
Which function in R applies a function to each element of a list or...
What does the 'purrr' package's map() function return?
In functional programming, immutability means that once a variable is...
Which R function reduces a list to a single value by applying a...
What is function composition in R?
The filter() function from 'purrr' returns elements that satisfy a...
In R, anonymous functions are often used in functional programming....
What does the Reduce() function do with the operation '+' on vector...
A pure function always produces the same output for the same input and...
Which of the following is a characteristic of functional programming...
In R, the 'magrittr' pipe operator is represented as ____.
What does sapply() do compared to lapply() in R?
Currying in functional programming refers to transforming a function...
The partial() function from 'purrr' allows you to fix some arguments...
play-Mute sad happy unanswered_answer up-hover down-hover success oval cancel Check box square blue
Alert!