The “list” Function in R

  • Package: Base R (no specific package required)

  • Purpose: Creates a list, an ordered collection of objects.

  • General Class: Data Manipulation

  • Required Argument(s):

    • Objects to be included in the list.

  • Notable Optional Arguments:

    • None

  • Example:

  • # Example data for using the list function
    names <- c("Alice", "Bob", "Charlie")
    ages <- c(25, 30, 22)

    # Create a list with two elements
    my_list <- list(Names = names, Ages = ages)

    # Display the result
    print(my_list)

  • In this example, the list function is used to create a list (my_list) with two elements, “Names” and “Ages.” The elements of the list are populated with data from the vectors names and ages. Lists in R can contain different types of objects and are a versatile data structure used for various purposes, including storing and organizing heterogeneous data.

Previous
Previous

The “array” Function in R

Next
Next

The “matrix” Function in R