Suppose I have a data frame like the following
a=data.frame(x=1:3,y=c("a","b","c"))
where y
is the key column. Sometimes I just want to look up a the value of x
corresponding to a key in y
. To accomplish this, I can
row.names(a)=a$y
a["b",c("x")]
Just like looking up a value of a given key in a Python dictionary.
Now I want to achieve the same thing using tidyverse's tibble. But since tibble does not have row.names
, I have no idea how to do it.
My question is, what is the "most clever" way (or idiomatic way, to borrow a term from Python) to look up a single value in a tibble given a single key?