https://github.com/wireservice/lookupr
Fetch common lookup tables and join them to your data. (A port of agate-lookup to R.)
https://github.com/wireservice/lookupr
data dplyr lookup r tables tidyverse
Last synced: 6 days ago
JSON representation
Fetch common lookup tables and join them to your data. (A port of agate-lookup to R.)
- Host: GitHub
- URL: https://github.com/wireservice/lookupr
- Owner: wireservice
- License: other
- Created: 2017-04-24T16:44:43.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-26T21:17:25.000Z (over 8 years ago)
- Last Synced: 2025-03-02T22:30:56.338Z (7 months ago)
- Topics: data, dplyr, lookup, r, tables, tidyverse
- Language: R
- Homepage:
- Size: 16.6 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```# lookupr
Lookup pulls common lookup tables from the [lookup](https://github.com/wireservice/lookup) repository and joins them to your data.
This is a port of Python's [agate-lookup](https://agate-lookup.readthedocs.io).
This version does not do caching. If you don't want to redownload lookup tables, save a local copy of your results.
## Install
From Github:
``` r
install.packages("devtools")
devtools::install_github("wireservice/lookupr")
```## Usage
Load libraries:
```{r, message = FALSE}
library(dplyr)
library(lookupr)
```Lookup the consumer price index for yearly data:
```{r}
data <- data.frame(year = c("2004", "2005", "2006", "2007"))data %>%
lookup("year", "cpi")
```If you're column name is different from `year`:
```{r}
data <- data.frame(anum = c("2004", "2005", "2006", "2007"))data %>%
lookup("anum", "cpi", lookup_keys = "year")
```Monthly CPI:
```{r}
data <- data.frame(
year = c("2004", "2004", "2005", "2005"),
month = c("11", "12", "1", "2")
)data %>%
lookup(c("year", "month"), "cpi", version="sa")
```## Inflation adjustment
As it's such a common use-case, lookup includes shortcut functions for doing CPI adjustment:
```{r}
data <- data.frame(
year = c("2005", "2006", "2007", "2008", "2009", "2010"),
price_a = c(100, 100, 100, 100, 100, 100),
price_b = c(200, 200, 200, 200, 200, 200)
)data %>%
lookup_cpi(c("price_a", "price_b"), base = "2010")
```