| 1 |
\name{collect} |
| 2 |
\alias{collect} |
| 3 |
\alias{collect.default} |
| 4 |
\alias{collect.array} |
| 5 |
\alias{collect.matrix} |
| 6 |
\alias{collect.table} |
| 7 |
\alias{collect.data.frame} |
| 8 |
\alias{collect.data.set} |
| 9 |
\title{Collect Objects} |
| 10 |
\description{ |
| 11 |
\code{collect} gathers several objects into one, matching the |
| 12 |
elements or subsets of the objects by \code{\link{names}} or \code{\link{dimnames}}. |
| 13 |
} |
| 14 |
\usage{ |
| 15 |
collect(\dots,names=NULL,inclusive=TRUE) |
| 16 |
\method{collect}{default}(\dots,names=NULL,inclusive=TRUE) |
| 17 |
\method{collect}{array}(\dots,names=NULL,inclusive=TRUE) |
| 18 |
\method{collect}{matrix}(\dots,names=NULL,inclusive=TRUE) |
| 19 |
\method{collect}{table}(\dots,names=NULL,sourcename=".origin",fill=0) |
| 20 |
\method{collect}{data.frame}(\dots,names=NULL,inclusive=TRUE, |
| 21 |
fussy=FALSE,warn=TRUE, |
| 22 |
detailed.warnings=FALSE,use.last=FALSE, |
| 23 |
sourcename=".origin") |
| 24 |
\method{collect}{data.set}(\dots,names=NULL,inclusive=TRUE, |
| 25 |
fussy=FALSE,warn=TRUE, |
| 26 |
detailed.warnings=FALSE,use.last=FALSE, |
| 27 |
sourcename=".origin") |
| 28 |
} |
| 29 |
\arguments{ |
| 30 |
\item{\dots}{more atomic vectors, arrays, matrices, tables, data.frames or data.sets} |
| 31 |
\item{names}{optional character vector; in case of the default and array methods, |
| 32 |
giving \code{\link{dimnames}} for the new dimension that identifies the |
| 33 |
collected objects; in case of the data.frame and data.set methods, |
| 34 |
levels of a factor indentifying the collected objects. |
| 35 |
} |
| 36 |
\item{inclusive}{logical, defaults to TRUE; should unmatched elements included? See details below.} |
| 37 |
\item{fussy}{logical, defaults to FALSE; should it count as an error, if variables with same |
| 38 |
names of collected data.frames/data.sets have different attributes?} |
| 39 |
\item{warn}{logical, defaults to TRUE; should an warning be given, if variables with same |
| 40 |
names of collected data.frames/data.sets have different attributes?} |
| 41 |
\item{detailed.warnings}{logical, whether the attributes of each |
| 42 |
variable should be printed if they differ, and if \code{warn} or |
| 43 |
\code{fuzzy} is TRUE.} |
| 44 |
\item{use.last}{logical, defaults to FALSE. If the function is |
| 45 |
applied to data frames or similar objects, attributes of variables |
| 46 |
may differ between data frames (or other objects, respectively). If |
| 47 |
this argument is TRUE, then the attributes are harmonised based on |
| 48 |
the variables in the last data frame/object, otherwise the |
| 49 |
attributes of variables in the first data frame/object are used for harmonisation. |
| 50 |
} |
| 51 |
\item{sourcename}{name of the factor that identifies the collected data.frames or data.sets} |
| 52 |
\item{fill}{numeric; with what to fill empty table cells, defaults to zero, assuming |
| 53 |
the table contains counts} |
| 54 |
} |
| 55 |
\value{ |
| 56 |
If \code{x} and all following \dots arguments are vectors of the same mode (numeric,character, or logical) |
| 57 |
the result is a matrix with as many columns as vectors. If argument \code{inclusive} is TRUE, |
| 58 |
then the number of rows equals the number of names that appear at least once in each of the |
| 59 |
vector names and the matrix is filled with \code{NA} where necessary, |
| 60 |
otherwise the number of rows equals the number of names that are present in \emph{all} |
| 61 |
vector names. |
| 62 |
|
| 63 |
If \code{x} and all \dots arguments are matrices or arrays of the same mode (numeric,character, or logical) |
| 64 |
and \eqn{n} dimension the result will be a \eqn{n+1} dimensional array or table. The extend of the |
| 65 |
\eqn{n+1}th dimension equals the number of matrix, array or table arguments, |
| 66 |
the extends of the lower dimension depends on the \code{inclusive} argument: |
| 67 |
either they equal to the number of dimnames that appear at least once for each given |
| 68 |
dimension and the array is filled with \code{NA} where necessary, |
| 69 |
or they equal to the number of dimnames that appear in all arguments |
| 70 |
for each given dimension. |
| 71 |
|
| 72 |
If \code{x} and all \dots arguments are data frames or data sets, the |
| 73 |
result is a data frame or data set. |
| 74 |
The number of variables of the resulting data frame or data set depends on |
| 75 |
the \code{inclusive} argument. If it is true, the number of variables |
| 76 |
equals the number of variables that appear in each of the arguments at least once |
| 77 |
and variables are filled with \code{NA} where necessary, otherwise the |
| 78 |
number of variables equals the number of variables that are present in |
| 79 |
all arguments. |
| 80 |
} |
| 81 |
\examples{ |
| 82 |
x <- c(a=1,b=2) |
| 83 |
y <- c(a=10,c=30) |
| 84 |
|
| 85 |
x |
| 86 |
y |
| 87 |
|
| 88 |
collect(x,y) |
| 89 |
collect(x,y,inclusive=FALSE) |
| 90 |
|
| 91 |
X <- matrix(1,nrow=2,ncol=2,dimnames=list(letters[1:2],LETTERS[1:2])) |
| 92 |
Y <- matrix(2,nrow=3,ncol=2,dimnames=list(letters[1:3],LETTERS[1:2])) |
| 93 |
Z <- matrix(3,nrow=2,ncol=3,dimnames=list(letters[1:2],LETTERS[1:3])) |
| 94 |
|
| 95 |
X |
| 96 |
Y |
| 97 |
Z |
| 98 |
|
| 99 |
collect(X,Y,Z) |
| 100 |
collect(X,Y,Z,inclusive=FALSE) |
| 101 |
|
| 102 |
X <- matrix(1,nrow=2,ncol=2,dimnames=list(a=letters[1:2],b=LETTERS[1:2])) |
| 103 |
Y <- matrix(2,nrow=3,ncol=2,dimnames=list(a=letters[1:3],c=LETTERS[1:2])) |
| 104 |
Z <- matrix(3,nrow=2,ncol=3,dimnames=list(a=letters[1:2],c=LETTERS[1:3])) |
| 105 |
|
| 106 |
collect(X,Y,Z) |
| 107 |
collect(X,Y,Z,inclusive=FALSE) |
| 108 |
|
| 109 |
df1 <- data.frame(a=rep(1,5),b=rep(1,5)) |
| 110 |
df2 <- data.frame(a=rep(2,5),b=rep(2,5),c=rep(2,5)) |
| 111 |
collect(df1,df2) |
| 112 |
collect(df1,df2,inclusive=FALSE) |
| 113 |
|
| 114 |
data(UCBAdmissions) |
| 115 |
Male <- as.table(UCBAdmissions[,1,]) |
| 116 |
Female <- as.table(UCBAdmissions[,2,]) |
| 117 |
collect(Male,Female,sourcename="Gender") |
| 118 |
collect(unclass(Male),unclass(Female)) |
| 119 |
|
| 120 |
Male1 <- as.table(UCBAdmissions[,1,-1]) |
| 121 |
Female2 <- as.table(UCBAdmissions[,2,-2]) |
| 122 |
Female3 <- as.table(UCBAdmissions[,2,-3]) |
| 123 |
collect(Male=Male1,Female=Female2,sourcename="Gender") |
| 124 |
collect(Male=Male1,Female=Female3,sourcename="Gender") |
| 125 |
collect(Male=Male1,Female=Female3,sourcename="Gender",fill=NA) |
| 126 |
|
| 127 |
f1 <- gl(3,5,labels=letters[1:3]) |
| 128 |
f2 <- gl(3,6,labels=letters[1:3]) |
| 129 |
collect(f1=table(f1),f2=table(f2)) |
| 130 |
|
| 131 |
ds1 <- data.set(x = 1:3) |
| 132 |
ds2 <- data.set(x = 4:9, |
| 133 |
y = 1:6) |
| 134 |
collect(ds1,ds2) |
| 135 |
|
| 136 |
} |
| 137 |
\keyword{utilities} |
| 138 |
\keyword{manip} |