fac.match: Match, for each combination of a set of columns in 'x', the...

Description Usage Arguments Value Author(s) See Also Examples

View source: R/fac.match.r

Description

Match, for each combination of a set of columns in x, the rows that has the same combination in table. The argument multiples.allow controls what happens when there are multple matches in table of a combination in x.

Usage

1
fac.match(x, table, col.names, nomatch = NA_integer_, multiples.allow = FALSE)

Arguments

x

an R object, normally a data.frame, possibly a matrix.

table

an R object, normally a data.frame, possibly a matrix.

col.names

A character vector giving the columns in x and table that are to be matched.

nomatch

The value to be returned in the case when no match is found. Note that it is coerced to integer.

multiples.allow

A logical indicating whether multiple matches of a combination in x to those in table is allowed. If multiples.allow is FALSE, an error is generated. If multiples.allow is TRUE, the first occuence in table is matched. This function can be viewed as a generalization to multiple vectors of the match function that applies to single vectors.

Value

A vector of length equal to x that gives the rows in table that match the combinations of col.names in x. The order of the rows is the same as the order of the combintions in x. The value returned if a combination is unmatched is specified in the nomatch argument.

Author(s)

Chris Brien

See Also

match

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Not run: 
#A single unmatched combination
kdata <- data.frame(Expt="D197-5", 
                    Row=8, 
                    Column=20, stringsAsFactors=FALSE)
index <- fac.match(kdata, D197.dat, c("Expt", "Row", "Column"))

# A matched and an unmatched combination
kdata <- data.frame(Expt=c("D197-5", "D197-4"), 
                    Row=c(8, 10), 
                    Column=c(20, 8), stringsAsFactors=FALSE)
index <- fac.match(kdata, D197.dat, c("Expt", "Row", "Column"))

## End(Not run)

dae documentation built on Nov. 7, 2019, 10:29 a.m.