| 1 |
\name{data.set manipulation} |
| 2 |
\alias{subset.data.set} |
| 3 |
\alias{unique,data.set-method} |
| 4 |
\alias{merge,data.set,data.set-method} |
| 5 |
\alias{merge,data.set,data.frame-method} |
| 6 |
\alias{merge,data.frame,data.set-method} |
| 7 |
\alias{cbind.data.set} |
| 8 |
\alias{rbind.data.set} |
| 9 |
\title{Manipulation of Data Sets} |
| 10 |
\description{ |
| 11 |
Like data frames, \code{data.set} objects have |
| 12 |
\code{\link[base]{subset}}, \code{\link[base]{unique}}, |
| 13 |
\code{\link[base]{cbind}}, \code{\link[base:cbind]{rbind}}, |
| 14 |
\code{\link[base]{merge}} methods defined for them. |
| 15 |
|
| 16 |
The semantics are basically the same as the methods defined |
| 17 |
for data frames in the \code{base} package, with the only difference |
| 18 |
that the return values are \code{data.set} objects. |
| 19 |
In fact, the methods described here are front-ends to the |
| 20 |
corresponding methods for data frames, which are constructed |
| 21 |
such that the "extra" information attached to variables within |
| 22 |
\code{data.set} objects, that is, to \code{item} objects. |
| 23 |
} |
| 24 |
\usage{ |
| 25 |
\method{subset}{data.set}(x, subset, select, drop = FALSE, \dots) |
| 26 |
|
| 27 |
\S4method{unique}{data.set}(x, incomparables = FALSE, \dots) |
| 28 |
|
| 29 |
\S3method{cbind}{data.set}(\dots, deparse.level = 1) |
| 30 |
|
| 31 |
\S3method{rbind}{data.set}(\dots, deparse.level = 1) |
| 32 |
|
| 33 |
\S4method{merge}{data.set,data.set}(x,y, \dots) |
| 34 |
|
| 35 |
\S4method{merge}{data.set,data.frame}(x,y, \dots) |
| 36 |
|
| 37 |
\S4method{merge}{data.frame,data.set}(x,y, \dots) |
| 38 |
} |
| 39 |
\arguments{ |
| 40 |
\item{x,y}{\code{data.set} objects. On of the arguments to |
| 41 |
\code{merge} may also be an object coercable into a data frame |
| 42 |
and the result still is a \code{data.set} object. |
| 43 |
} |
| 44 |
\item{subset}{a logical expression, used to select observations from |
| 45 |
the data set.} |
| 46 |
\item{select}{a vector with variablen names, which are retained in the |
| 47 |
data subset.} |
| 48 |
\item{drop}{logical; if \code{TRUE} and the result has only one |
| 49 |
column, the result is an item and not a data set.} |
| 50 |
\item{\dots}{for \code{subset}: a logical vector |
| 51 |
of the same length as the number of rows of the \code{data.set} |
| 52 |
and, optionally, a vector of variable names (tagged as \code{select}); |
| 53 |
for \code{unique}: further arguments, ignored; |
| 54 |
for \code{cbind}, \code{rbind}: objects coercable |
| 55 |
into data frames, with at least one being a \code{data.set} |
| 56 |
object; |
| 57 |
for \code{merge}: further arguments |
| 58 |
such as arguments tagged with \code{by}, \code{by.x}, \code{by.y}, |
| 59 |
etc. that specify the variables by which to merge |
| 60 |
the data sets of data frames \code{x} and \code{y}. |
| 61 |
} |
| 62 |
\item{incomparables}{a vector of values that cannot be compared. See |
| 63 |
\code{\link[base]{unique}}. |
| 64 |
} |
| 65 |
\item{deparse.level}{an argument retained for |
| 66 |
reasons of compatibility of the default methods |
| 67 |
of \code{\link[base]{cbind}} and \code{\link[base:cbind]{rbind}}. |
| 68 |
} |
| 69 |
} |
| 70 |
\examples{ |
| 71 |
ds1 <- data.set( |
| 72 |
a = rep(1:3,5), |
| 73 |
b = rep(1:5,each=3) |
| 74 |
) |
| 75 |
ds2 <- data.set( |
| 76 |
a = c(3:1,3,3), |
| 77 |
b = 1:5 |
| 78 |
) |
| 79 |
|
| 80 |
ds1 <- within(ds1,{ |
| 81 |
description(a) <- "Example variable 'a'" |
| 82 |
description(b) <- "Example variable 'b'" |
| 83 |
}) |
| 84 |
|
| 85 |
ds2 <- within(ds2,{ |
| 86 |
description(a) <- "Example variable 'a'" |
| 87 |
description(b) <- "Example variable 'b'" |
| 88 |
}) |
| 89 |
|
| 90 |
str(ds3 <- rbind(ds1,ds2)) |
| 91 |
description(ds3) |
| 92 |
|
| 93 |
ds3 <- within(ds1,{ |
| 94 |
c <- a |
| 95 |
d <- b |
| 96 |
description(c) <- "Copy of variable 'a'" |
| 97 |
description(d) <- "Copy of variable 'b'" |
| 98 |
rm(a,b) |
| 99 |
}) |
| 100 |
str(ds4 <- cbind(ds1,ds3)) |
| 101 |
description(ds4) |
| 102 |
|
| 103 |
ds5 <- data.set( |
| 104 |
c = 1:3, |
| 105 |
d = c(1,1,2) |
| 106 |
) |
| 107 |
ds5 <- within(ds5,{ |
| 108 |
description(c) <- "Example variable 'c'" |
| 109 |
description(d) <- "Example variable 'd'" |
| 110 |
}) |
| 111 |
str(ds6 <- merge(ds1,ds5,by.x="a",by.y="c")) |
| 112 |
|
| 113 |
# Note that the attributes of the left-hand variables |
| 114 |
# have priority. |
| 115 |
description(ds6) |
| 116 |
} |