list
List Objects

### Description

Creates or tests for lists (objects with mode list).

### Usage

    list(...)
    is.list(x)
    as.list(x, ...)
    ## S3 method for class 'Date':
    as.list(x, ...)
    ## S3 method for class 'POSIXct':
    as.list(x, ...)
    ## S3 method for class 'environment':
    as.list(x, all.names = FALSE, sorted = FALSE, ...)

### Arguments

... | any arguments, with any names.
x | any object.
all.names | a logical value used only by as.list.environment. If TRUE, hidden objects (those whose names begin with a period) are included. The default is FALSE.
sorted | a logical value used only by as.list.environment. If TRUE, the returned list's components are ordered so that their names are in alphabetical order. The default is FALSE, meaning that the order is arbitrary.

### Details

The constructor function for lists is different from the constructor for atomic modes, which takes the desired length as an argument. To generate a list of length 10 when you do not know initially what the elements should be, use vector("list", 10).
Lists are simple objects (see vector) when they have no attributes, other than names. For example, it is possible to have a matrix, an array, or a time series of mode list.
Value

list | returns an object of mode list, with as many components as there are arguments. The individual arguments become the components of the list, and the argument names, if any, are the corresponding elements of the names attribute of the list.
is.list | returns a logical value: TRUE if x has mode "list"; otherwise it returns FALSE.
as.list | returns x if x is a simple object of mode "list"; otherwise, it returns a list object of the same length as x. If x is an atomic object, the elements of the list are objects of length 1, containing the individual elements of x. If x is a recursive object, its elements are unchanged. Attributes are deleted. The as.list function is generic. Some methods are implemented for the following classes: "data.frame" "Date" "factor" "environment" "function" "numeric_version" "POSIXct" The default method is as.list.default, which calls as.vector(x, mode="list") unless the input is already a list, in which case it just returns its input. Note that as.vector is generic.

See Also
c, unlist, mode, vector, Date, POSIXt
Examples

    x <- 1:5
    list(original=x, square=x^2)
    as.list(1:10) # ten integer components
    list (1:10) # one component
    # the arguments can themselves be lists
    # and some components can be named while others are not
    list(1:10, col="brown", list(5:15, 3:7, 34:39))
    e <- new.env()
    e$x <- 1:3
    e$.foo <- 42  # Hidden
    e$y <- 'abc'
    as.list(e) # a list with y and x;  as list for environment
    as.list(e, all.names = TRUE) # a list with y, .foo, and x
    df <- data.frame(Name = c("Mike","Tom","Mary"),
        Gender = c("M", "M", "F"), Age = c(25, 32, 22))
    as.list(df)  # as list for  data frame
    as.list(df$Name)  # as list for factor
    as.list(factor) # as list for function "factor"
    ## Date
    d <- as.Date(c("1970-01-01", "2038-01-19"))
    as.list(d)
    ## POSIXct
    pct <- as.POSIXct(c("1970-01-01 00:00:00", "2038-01-19 03:14:07"))
    as.list(pct)
    xn <- numeric_version(1:12)
    as.list(xn) # as list for numeric_version

Package base version 6.1.5-18
Package Index