vlookup | R Documentation |
If you've ever used excel, then you are hopefully familiar with the useful
vlookup
. This is a fun little version of it in R that was tweeted by Jenny
Bryan at some point.
Match on the key
and return value
.
vlookup(this, data, key, value)
this |
Value or vector; what you are trying to look up |
data |
Data frame; the data where you want to match |
key |
The name (quoted) of the column to match on |
value |
The name (quoted) of the column to return |
A vector of values
https://twitter.com/JennyBryan/status/980978609794895872/photo/1
library(dplyr)
head(starwars)
c("Luke Skywalker", "Jabba Desilijic Tiure", "Yoda") %>%
vlookup(this = .,
data = starwars,
key = "name",
value = "species")
c("Luke Skywalker", "Jabba Desilijic Tiure", "Yoda") %>%
vlookup(this = ., data = starwars, key = "name", value = "mass") %>%
sum(.)
c("Luke Skywalker", "Jabba Desilijic Tiure", "Yoda") %>%
vlookup(data = starwars, key = "name", value = "mass") %>%
sum(.)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.