c
Combine Values into a Vector or List

Description

Concatenates objects into a vector or a list. The result is an atomic list if all of the objects are atomic; otherwise, the result is a list.

Usage

c(..., recursive = FALSE)
## S3 method for class 'Date':
c(..., recursive = FALSE)
## S3 method for class 'POSIXct':
c(..., recursive = FALSE)
## S3 method for class 'POSIXlt':
c(..., recursive = FALSE)

Arguments

... any objects. Missing values (NAs) are allowed. The names of arguments become part of the names of the resulting vector.
recursive a logical value. If TRUE, indicates that the combining should be done recursively. The default is FALSE.

Details

Arguments that are NULL or length 0 do not contribute elements to the result.
Note that c(...,recursive=TRUE) is equivalent to unlist(list(...), recursive=TRUE).
Value
returns a vector or a list that is the combination of all values from all arguments to the function. If recursive is TRUE, arguments with recursive modes are effectively unlisted (see unlist) before they are used.
The mode of the result is the most general of all the modes in the arguments (or the unlisted arguments, if recursive=TRUE). In particular, list objects can be combined this way.
The names attribute of the result is generated from the argument names, if any, plus the names of the combined objects. See unlist for the rule used. Attributes of objects that are bound with other objects are deleted.
The c.Date(), c.POSIXct() and c.POSIXlt() return combined date-time objects of their respective class type.
See Also
concat, append, cbind, unlist
Examples
c(1:10, 1:5, 1:10)
c(2, 3, 5, 7, 11, 13)
c(a=1, b=2)  # vector with names "a" and "b"
c(Sdatasets::state.name, "Washington DC")
# a list of 4 numeric vectors
c(list(1:3, a=3:6), list(8:23, c(3, 8, 39)))
# a numeric vector of length 26
c(list(1:3, a=3:6), list(8:23, c(3, 8, 39)), recursive=TRUE)
# build x, element by element
# useful if final length not known in advance
## Not run: 
x <- numeric(0)
for(i in possibles)
  if(test(i)) x <- c(x, fun(i))

## End(Not run)

## combine date-time objects c(Sys.Date() + 365, Sys.Date() + 2, as.Date("2009-12-12")) c(Sys.time() + 365, Sys.time() + 2, as.POSIXct("2009-12-12 01:02:03")) c(as.POSIXlt(Sys.time() + 365), as.POSIXlt(Sys.time() + 2), as.POSIXlt("2009-12-12 01:02:03"))

Package base version 4.0.0-28
Package Index