Skip to content

Commit

Permalink
Added %oin%.
Browse files Browse the repository at this point in the history
  • Loading branch information
mhahsler committed Aug 5, 2017
1 parent f528a8e commit 9bb4b95
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ exportClasses(
exportMethods(
"%in%",
"%ain%",
"%oin%",
"%pin%",
"LIST",
"DATAFRAME",
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## New Features
* apriori and eclat return now count (absolute support count) in the
quality data.frame.
* Added %oin% to find transactions/itemsets that ONLY contain certain items.

## Bug Fixes
* Improved PROTECT placement in C source code.
Expand Down
3 changes: 3 additions & 0 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ setGeneric("%pin%",
setGeneric("%ain%",
function(x, table) standardGeneric("%ain%"))

setGeneric("%oin%",
function(x, table) standardGeneric("%oin%"))

setGeneric("LIST",
function(from, ...) standardGeneric("LIST"))

Expand Down
10 changes: 10 additions & 0 deletions R/itemMatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ setMethod("%ain%", signature(x = "itemMatrix", table = "character"),
}
)

## all items have to be in
setMethod("%oin%", signature(x = "itemMatrix", table = "character"),
function(x, table) {
pos <- match(table, itemLabels(x))
if (any(is.na(pos)))
stop("table contains an unknown item label" )
size(x[, -pos]) == 0
}
)

## partial in
setMethod("%pin%", signature(x = "itemMatrix", table = "character"),
function(x, table) {
Expand Down
7 changes: 7 additions & 0 deletions man/itemMatrix-class.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
\alias{\%pin\%,itemMatrix,character-method}
\alias{\%ain\%}
\alias{\%ain\%,itemMatrix,character-method}
\alias{\%oin\%}
\alias{\%oin\%,itemMatrix,character-method}
\alias{itemLabels<-,itemMatrix-method}
\alias{itemLabels,itemMatrix-method}
\alias{itemLabels<-}
Expand Down Expand Up @@ -143,6 +145,11 @@ See \code{\link{itemCoding}} to learn how to encode and recode itemMatrix object
in \code{x} and returns a logical vector indicating if
a row (itemset) in \code{x} contains \emph{all} of the
items specified in \code{table}.}
\item{\%oin\%}{\code{signature(x = "itemMatrix", table = "character")};
matches the strings in \code{table} against the item labels
in \code{x} and returns a logical vector indicating if
a row (itemset) in \code{x} contains \emph{only}
items specified in \code{table}.}
\item{\%pin\%}{\code{signature(x = "itemMatrix", table = "character")};
matches the strings in \code{table} against the item labels
in \code{x} (using \emph{partial} matching) and returns a
Expand Down

0 comments on commit 9bb4b95

Please sign in to comment.