What is the list() function in R?
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 functiona = c(1, 2, 3, 4, 5)b = c("A", "B", "C", "D", "E")c = c("A", "B", "c", "1", "2")# implementing the list() functionlist(a, b, c)
Explanation
- Lines 2–4: We create the R objects,
a,b, andcthat will serve as the argument to thelist()function. - Line 7: We call the
list()function and passed the objectsa,b, andcas its arguments. We print the result to the console.