| 42333 |
ripley |
1 |
% File src/library/base/man/c.Rd
|
| 68948 |
ripley |
2 |
% Part of the R package, https://www.R-project.org
|
| 71956 |
ripley |
3 |
% Copyright 1995-2017 R Core Team
|
| 42333 |
ripley |
4 |
% Distributed under GPL 2 or later
|
| 2 |
r |
5 |
\name{c}
|
|
|
6 |
\title{Combine Values into a Vector or List}
|
| 71398 |
maechler |
7 |
\alias{c}
|
|
|
8 |
\alias{c.default}% existing "conceptually", see ../../tools/R/QC.R
|
| 2 |
r |
9 |
\usage{
|
| 71398 |
maechler |
10 |
## S3 Generic function
|
|
|
11 |
c(\dots)
|
|
|
12 |
|
|
|
13 |
\S3method{c}{default}(\dots, recursive = FALSE, use.names = TRUE)
|
| 2 |
r |
14 |
}
|
|
|
15 |
\description{
|
| 15518 |
ripley |
16 |
This is a generic function which combines its arguments.
|
| 20997 |
maechler |
17 |
|
| 15518 |
ripley |
18 |
The default method combines its arguments to form a vector.
|
|
|
19 |
All arguments are coerced to a common type which is the type
|
| 39908 |
ripley |
20 |
of the returned value, and all attributes except names are removed.
|
| 2 |
r |
21 |
}
|
| 15518 |
ripley |
22 |
\arguments{
|
|
|
23 |
\item{\dots}{objects to be concatenated.}
|
| 38278 |
ripley |
24 |
\item{recursive}{logical. If \code{recursive = TRUE}, the function
|
|
|
25 |
recursively descends through lists (and pairlists) combining all
|
|
|
26 |
their elements into a vector.}
|
| 71323 |
maechler |
27 |
\item{use.names}{logical indicating if \code{\link{names}} should be
|
|
|
28 |
preserved.}
|
| 15518 |
ripley |
29 |
}
|
| 38278 |
ripley |
30 |
\details{
|
|
|
31 |
The output type is determined from the highest type of the components
|
| 61598 |
ripley |
32 |
in the hierarchy NULL < raw < logical < integer < double < complex < character
|
| 71862 |
ripley |
33 |
< list < expression. Pairlists are treated as lists, whereas non-vector
|
| 38278 |
ripley |
34 |
components (such names and calls) are treated as one-element lists
|
|
|
35 |
which cannot be unlisted even if \code{recursive = TRUE}.
|
| 39908 |
ripley |
36 |
|
| 70994 |
maechler |
37 |
%% Should we say "(currently)" ?
|
|
|
38 |
Note that \code{\link{factor}}s are treated only via their
|
|
|
39 |
internal \code{\link{integer}} codes; one proposal has been to use
|
|
|
40 |
\preformatted{ c.factor <- function(..., recursive=TRUE) unlist(list(...), recursive=recursive)}
|
|
|
41 |
if factor concatenation by \code{c()} should give a \code{\link{factor}}.
|
|
|
42 |
|
| 39908 |
ripley |
43 |
\code{c} is sometimes used for its side effect of removing attributes
|
|
|
44 |
except names, for example to turn an array into a vector.
|
| 46739 |
ripley |
45 |
\code{as.vector} is a more intuitive way to do this, but also drops
|
| 71862 |
ripley |
46 |
names. Note that methods other than the default are not required
|
| 46739 |
ripley |
47 |
to do this (and they will almost certainly preserve a class attribute).
|
| 61433 |
ripley |
48 |
|
| 48662 |
ripley |
49 |
This is a \link{primitive} function.
|
| 38278 |
ripley |
50 |
}
|
|
|
51 |
\value{
|
|
|
52 |
\code{NULL} or an expression or a vector of an appropriate mode.
|
| 61433 |
ripley |
53 |
(With no arguments the value is \code{NULL}.)
|
| 38278 |
ripley |
54 |
}
|
| 42270 |
ripley |
55 |
\section{S4 methods}{
|
| 41286 |
ripley |
56 |
This function is S4 generic, but with argument list
|
| 72564 |
maechler |
57 |
\code{(x, ...)}.
|
| 41286 |
ripley |
58 |
}
|
| 24300 |
ripley |
59 |
\references{
|
|
|
60 |
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
|
|
|
61 |
\emph{The New S Language}.
|
| 47262 |
ripley |
62 |
Wadsworth & Brooks/Cole.
|
| 24300 |
ripley |
63 |
}
|
| 2 |
r |
64 |
\seealso{
|
| 15518 |
ripley |
65 |
\code{\link{unlist}} and \code{\link{as.vector}} to produce
|
|
|
66 |
attribute-free vectors.
|
| 2 |
r |
67 |
}
|
|
|
68 |
\examples{
|
|
|
69 |
c(1,7:9)
|
|
|
70 |
c(1:5, 10.5, "next")
|
| 1935 |
maechler |
71 |
|
| 39908 |
ripley |
72 |
## uses with a single argument to drop attributes
|
|
|
73 |
x <- 1:4
|
|
|
74 |
names(x) <- letters[1:4]
|
|
|
75 |
x
|
|
|
76 |
c(x) # has names
|
|
|
77 |
as.vector(x) # no names
|
|
|
78 |
dim(x) <- c(2,2)
|
|
|
79 |
x
|
|
|
80 |
c(x)
|
|
|
81 |
as.vector(x)
|
|
|
82 |
|
| 20997 |
maechler |
83 |
## append to a list:
|
| 61150 |
ripley |
84 |
ll <- list(A = 1, c = "C")
|
| 23011 |
ripley |
85 |
## do *not* use
|
| 74363 |
maechler |
86 |
c(ll, d = 1:3) # which is == c(ll, as.list(c(d = 1:3)))
|
| 20997 |
maechler |
87 |
## but rather
|
| 61168 |
ripley |
88 |
c(ll, d = list(1:3)) # c() combining two lists
|
| 20997 |
maechler |
89 |
|
| 61150 |
ripley |
90 |
c(list(A = c(B = 1)), recursive = TRUE)
|
| 1935 |
maechler |
91 |
|
| 61150 |
ripley |
92 |
c(options(), recursive = TRUE)
|
|
|
93 |
c(list(A = c(B = 1, C = 2), B = c(E = 7)), recursive = TRUE)
|
| 2 |
r |
94 |
}
|
| 286 |
maechler |
95 |
\keyword{manip}
|