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, ...)
... | 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. |
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.
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. |
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