matchval: Lookup a value

Description Usage Arguments Details Value See Also Examples

Description

Lookup a value based on matching IDs among two data.frames.

Usage

1
matchval(x, y, val = NULL, xid = NULL, yid = NULL)

Arguments

x

data.frame containing values of interest.

y

data.frame to be matched.

val

character, name of column containing values in x.

xid

character, name of ID column in x.

yid

character, name of ID column in y.

Details

Similar to vlookup function found elsewhere. Returns NA if no match is found. If any IDs are duplicated, then only the first matching value is returned (just like match).

Value

Values from x$val, ordered by y$yid.

See Also

match.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
x <- data.frame(ident = letters[1:7], foo = rnorm(7))
y <- data.frame(ident = letters[5:9], bar = rnorm(5))
y$foo <- matchval(x, y, 'foo')
x
y

# be careful you use the intended column name!
colnames(y)[1] <- 'identifier'
matchval(x, y, 'foo')  # wrongly matches on existing 'foo' column
matchval(x, y, 'foo', 'ident', 'identifier')  # correct

phytomosaic/ecole documentation built on Jan. 2, 2022, 11:24 p.m.