Description Usage Arguments Details Value See Also Examples
Lookup a value based on matching IDs among two data.frames.
1 |
x |
data.frame containing values of interest. |
y |
data.frame to be matched. |
val |
character, name of column containing values in |
xid |
character, name of ID column in |
yid |
character, name of ID column in |
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
).
Values from x$val
, ordered by y$yid
.
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.