Trusted answers to developer questions

What is the list() function in R?

Onyejiaku Theophilus Chidalu

Grokking the Behavioral Interview

Get Educative’s popular interview prep course for free.

Overview

The list() function in R is used to create a list of elements of different types. A list can contain numeric, string, or vector elements.

Syntax

list(...)
Syntax for the list() function in R

Parameter value

The list() function takes a parameter value ...indicating the R objects, which may or may not be named.

Return value

The list() function returns a list that is composed of the arguments passed to it.

Code

# creating Objects as arguments for the list function
a = c(1, 2, 3, 4, 5)
b = c("A", "B", "C", "D", "E")
c = c("A", "B", "c", "1", "2")
# implementing the list() function
list(a, b, c)
Implementing the list() function

Explanation

  • Lines 2–4: We create the R objects, a, b, and c that will serve as the argument to the list() function.
  • Line 7: We call the list() function and passed the objects a, b, and c as its arguments. We print the result to the console.

RELATED TAGS

list
function
r

CONTRIBUTOR

Onyejiaku Theophilus Chidalu
Trusted Answers to Developer Questions

Related Tags

list
function
r
Keep Exploring
Related Courses