list: Create a list

View source: R/list.R

listR Documentation

Create a list

Description

Combine elements to form a list. A list is a very flexible data structure. Elements of a list can be named or unnamed, can have different lengths, can have different data types, and can even be lists themselves.

Details

list(...)

See Also

Other R data structures: c(), tibble()

purrr functions: map(), map2(), pmap()

Examples

# Lists can have elements of different
# data types:

list(1, 2, "apple", TRUE)

#> [[1]]
#> [1] 1

#> [[2]]
#> [1] 2

#> [[3]]
#> [1] "apple"

#> [[4]]
#> [1] TRUE

---------------------------------------

# Lists can have elements of different
# lengths:

list(
  1,
  c(1, 2, 3),
  c(TRUE, FALSE)
)

#> [[1]]
#> [1] 1

#> [[2]]
#> [1] 1 2 3

#> [[3]]
#> [1]  TRUE FALSE

---------------------------------------

# List elements can be named or unnamed:

list(
  numbers = 1:10,
  c("apple", "banana", "economics")
)

#> $numbers
#> [1]  1  2  3  4  5  6  7  8  9 10

#> [[2]]
#> [1] "apple" "banana" "economics"


cobriant/qelp documentation built on July 1, 2022, 7:24 a.m.