Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

classify

Value Matching for Data Frames


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

classify(x, table, ...)

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

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)),]

TRAMPR

'TRFLP' Analysis and Matching Package for R

v1.0-10
GPL-2
Authors
Rich FitzJohn [aut, cre], Ian Dickie [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.