-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
84 lines (59 loc) · 1.61 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{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")
```