What’s the state abbreviation for Arkansas? Is it AR? AK? AS?
Maybe you’ve got a data frame with the information. Or any info where there’s one column with categories, and another column with values. Chances are, at some point you’d like to look up the value by category, sometimes known as the key. A lot of programming languages have ways to work with key-value pairs. This is easy to do in R, too, with named vectors. Here’s how.
[ Get Sharon Machlis’s R tips in our how-to video series. | Read the InfoWorld tutorials: Learn to crunch big data with R. • How to reshape data in R. • R data manipulation tricks at your fingertips • Beginner’s guide to R. | Stay up to date on analytics and big data with the InfoWorld Big Data Report newsletter. ]
I’ve got data with state names and abbreviations, which I've stored in a data frame named
postal_df. (The code to create that data frame is at the bottom of this post if you'd like to follow along).
To read this article in full, please click here