This repository has been archived by the owner on Jul 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
121 lines (90 loc) · 2.66 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# taitratools <a href=''><img src='man/figures/logo.png' align="right" height="138.5" /></a>
<!-- badges: start -->
<!-- badges: end -->
Taitra Tools package gather all useful helper functions.
Most function in `taitratools` are prefix with `tt_`.
You can list all source path with `tt_ls()` funciton, read data with `tt_read_table()` or `tt_read_mof()` ...
``` r
# install.packages("devtools")
devtools::install_github("chinhungtseng/taitratools")
```
## Example
### Get data source path
```{r, include=FALSE}
library(taitratools)
tt_ls()
```
### Read data
* Get source path with `tt_get_path(PATH NAME)`
* Read file with `tt_read_table`
```{r, eval = FALSE}
path <- tt_get_path("PATH_AREA")
path
area_tbl <- tt_read_table(path)
head(area_tbl)
```
* read mof data
* `tt_vroom_mof()`
* `tt_read_mof()`
This is a basic example which shows you how to read data from MOF,
if you want to read data with past year, you can set `period = N`
```{r, eval = FALSE}
# Default is `export` and `usd`
mof_data <- tt_vroom_mof("2019-01", "2019-02", period = 1, direct = "export", money = "usd", dep_month_cols = TRUE)
head(mof_data)
```
### Data Transform
#### Industry data transforming
* `tt_bind_industry()`
* `tt_industry_grouped_sum()`
```{r, eval = FALSE}
# industry_type => "all_industry", "industry21", "version1", "version2"
mof_data %>%
tt_bind_industry(sub = 8, col_more = TRUE, industry_type = "industry21", verbose = FALSE) %>%
head(5)
```
```{r, eval = FALSE}
mof_industry_data <- mof_data %>%
tt_industry_grouped_sum(industry_type = "industry21", sub = 6, verbose = FALSE)
str(mof_industry_data)
head(mof_industry_data$data, 5)
```
#### Area data transforming
* `tt_bind_area()`
* `tt_append_global()`
* `tt_append_area()`
Adding a area column
```{r, eval = FALSE}
mof_industry_data$data %>% tt_bind_area() %>% head(5)
```
Append area data
```{r, eval = FALSE}
mof_industry_data$data %>% tt_append_area() %>% head(5)
```
Append only world data
```{r, eval = FALSE}
mof_industry_data$data %>% tt_append_global() %>% head(5)
```
#### Others
* `tt_grouped_sum()`
* `tt_df_sub_hscode()`
grouped data and sum the value
```{r, eval = FALSE}
mof_data %>% tt_grouped_sum(country, year, by = "value") %>% head(5)
mof_data %>% tt_grouped_sum(year, month, by = "count") %>% head(5)
mof_data %>%
tt_bind_industry(industry_type = "industry21", verbose = FALSE) %>%
tt_grouped_sum(industry, country, year, by = "weight") %>% head(5)
```