classify: Value Matching for Data Frames

Description Usage Arguments Details Value See Also Examples

View source: R/util.R

Description

match-like classification for data.frames; returns a vector of row numbers of (first) matches of its first argument in its second, across shared column names. This is unlikely to be useful to casual TRAMP users, but see the final example for a relevant usage.

Usage

1

Arguments

x

data.frame: containing columns with the values to be matched.

table

data.frame: where all columns contain the values to be matched against.

...

Additional arguments to match (see especially nomatch).

Details

As with duplicated.data.frame, this works by pasting together a character representation of the rows separated by \r (a carriage return), so may be imperfect if the data.frame has characters with embedded carriage returns or columns which do not reliably map to characters.

Cases in x with NA values in any column shared with table will not be matched (and will return the value of nomatch). Cases in table with any NA values in any row will match nothing.

All columns in table must be present in x, but x may have additional columns that will be ignored.

Value

A vector of length nrow(x), with each element giving the row number in table where all elements match across shared columns.

See Also

match, on which this is based.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
table <- data.frame(a=letters[1:3], b=rep(1:2, each=3))
x <- cbind(table[sample(nrow(table), 20, TRUE),], x=runif(20))

classify(x, table)
all.equal(table[classify(x, table),], x[names(table)])

## Select only a few cases from a TRAMPsamples data object,
## corresponding with 4 enzyme/primer combinations.
data(demo.samples)
d <- demo.samples$data
use <- expand.grid(primer=c("ITS1F", "ITS4"),
                   enzyme=c("HpyCH4IV", "BsuRI"))
classify(d, use)
d[!is.na(classify(d, use)),]

richfitz/TRAMPR documentation built on Feb. 10, 2022, 3:10 p.m.