\HeaderA{combine}{Methods for Function combine in Package `Biobase'}{combine}
\aliasA{combine,data.frame,data.frame-method}{combine}{combine,data.frame,data.frame.Rdash.method}
\keyword{manip}{combine}
\begin{Description}\relax
This generic function handles methods for combining or merging different
Bioconductor data structures. It should, given an arbitrary number of
arguments of the same class (possibly by inheritance), combine them into
a single instance in a sensible way (some methods may only combine 2
objects, ignoring \code{...} in the argument list; because Bioconductor
data structures are complicated, check carefully that \code{combine}
does as you intend).
\end{Description}
\begin{Usage}
\begin{verbatim}
combine(x, y, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] One of the values. 
\item[\code{y}] A second value. 
\item[\code{...}] Any other objects of the same class as \code{x} and \code{y}. 
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
There are two basic combine strategies. One is an intersection
strategy. The returned value should only have rows (or columns) that
are found in all input data objects. The union strategy says that the
return value will have all rows (or columns) found in any one of the
input data objects (in which case some indication of what to use for
missing values will need to be provided).

These functions and methods are currently under construction. Please
let us know if there are features that you require.
\end{Details}
\begin{Value}
A single value of the same class as the most specific common ancestor
(in class terms) of the input values. This will contain the
appropriate combination of the data in the input values.
\end{Value}
\begin{Section}{Methods}
\describe{
\item[\code{combine(data.frame, data.frame)}] Combines two
\code{data.frame} objects so that the resulting \code{data.frame}
contains all rows and columns of the original objects. Rows and
columns in the returned value are unique, that is, a row or column
represented in both arguments is represented only once in the
result. To perform this operation, \code{combine} makes sure that data
in shared rows and columns are identical in the two
data.frames. Data differences in shared rows and columns cause an
error. \code{combine} issues a warning when a column is a
\code{\LinkA{factor}{factor}} and the levels of the factor in the two
\code{data.frame}s are different; this will usually result in an
error, as illustrated in the example.
}
Additional \code{combine} methods are defined for
\code{\LinkA{AnnotatedDataFrame}{AnnotatedDataFrame}},
\code{\LinkA{AssayData}{AssayData}}, \code{\LinkA{MIAME}{MIAME}}, and \code{\LinkA{eSet}{eSet}}
classes and subclasses.
\end{Section}
\begin{Author}\relax
Biocore
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{merge}{merge}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
  x <- data.frame(x=1:5,
          y=factor(letters[1:5], levels=letters[1:7]),
          row.names=letters[1:5])
  y <- data.frame(z=3:7,
          y=factor(letters[3:7], levels=letters[1:7]),
          row.names=letters[3:7])
  combine(x,y)

  # y is converted to 'factor' with different levels
  df1 <- data.frame(x=1:5,y=letters[1:5], row.names=letters[1:5])
  df2 <- data.frame(z=3:7,y=letters[3:7], row.names=letters[3:7])
  try(combine(df1, df2)) # fails
  # solution 1: ensure identical levels
  y1 <- factor(letters[1:5], levels=letters[1:7])
  y2 <- factor(letters[3:7], levels=letters[1:7])
  df1 <- data.frame(x=1:5,y=y1, row.names=letters[1:5])
  df2 <- data.frame(z=3:7,y=y2, row.names=letters[3:7])
  combine(df1, df2)
  # solution 2: force column to be 'character'
  df1 <- data.frame(x=1:5,y=I(letters[1:5]), row.names=letters[1:5])
  df2 <- data.frame(z=3:7,y=I(letters[3:7]), row.names=letters[3:7])
  combine(df1, df2)
\end{ExampleCode}
\end{Examples}

