R - Combine Values Into A Vector or List
R - Combine Values Into A Vector or List
R - Combine Values Into A Vector or List
html
c {base} R Documentation
Description
The default method combines its arguments to form a vector. All arguments are coerced to a
common type which is the type of the returned value, and all attributes except names are removed.
Usage
## S3 Generic function
c(...)
## Default S3 method:
c(..., recursive = FALSE, use.names = TRUE)
Arguments
...
objects to be concatenated.
recursive
logical. If recursive = TRUE, the function recursively descends through lists (and
pairlists) combining all their elements into a vector.
use.names
logical indicating if names should be preserved.
Details
The output type is determined from the highest type of the components in the hierarchy NULL <
raw < logical < integer < double < complex < character < list < expression. Pairlists are treated as
lists, whereas non-vector components (such names and calls) are treated as one-element lists which
cannot be unlisted even if recursive = TRUE.
Note that factors are treated only via their internal integer codes; one proposal has been to use
c is sometimes used for its side effect of removing attributes except names, for example to turn an
array into a vector. as.vector is a more intuitive way to do this, but also drops names. Note that
methods other than the default are not required to do this (and they will almost certainly preserve a
class attribute).
Value
1 of 2 18/Sep/2017, 10:50 PM
R: Combine Values into a Vector or List http://127.0.0.1:28599/library/base/html/c.html
NULL or an expression or a vector of an appropriate mode. (With no arguments the value is NULL.)
S4 methods
References
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth &
Brooks/Cole.
See Also
Examples
c(1,7:9)
c(1:5, 10.5, "next")
## append to a list:
ll <- list(A = 1, c = "C")
## do *not* use
c(ll, d = 1:3) # which is == c(ll, as.list(c(d = 1:3))
## but rather
c(ll, d = list(1:3)) # c() combining two lists
2 of 2 18/Sep/2017, 10:50 PM