## S3 Generic function
c(…)# S3 method for default
c(…, recursive = FALSE, use.names = TRUE)
recursive = TRUE
, the function
recursively descends through lists (and pairlists) combining all
their elements into a vector.names
should be
preserved.NULL
or an expression or a vector of an appropriate mode.
(With no arguments the value is NULL
.)(x, ...)
.recursive = TRUE
.
Note that factor
s are treated only via their
internal integer
codes; one proposal has been to use
c.factor <- function(..., recursive=TRUE) unlist(list(...), recursive=recursive)if factor concatenation by
c()
should give a factor
. 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). This is a primitive function.unlist
and as.vector
to produce
attribute-free vectors.c(1,7:9)
c(1:5, 10.5, "next")
## uses with a single argument to drop attributes
x <- 1:4
names(x) <- letters[1:4]
x
c(x) # has names
as.vector(x) # no names
dim(x) <- c(2,2)
x
c(x)
as.vector(x)
## 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
c(list(A = c(B = 1)), recursive = TRUE)
c(options(), recursive = TRUE)
c(list(A = c(B = 1, C = 2), B = c(E = 7)), recursive = TRUE)
Run the code above in your browser using DataLab