有人宣稱台灣有很多老舊過時的法規
是否可以在資料上看到法規更新的狀況?
library(jsonlite)
library(dplyr)
##
## Attaching package: 'dplyr'
##
## The following objects are masked from 'package:stats':
##
## filter, lag
##
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(lubridate)
library(tidyr)
library(stringr)
library(ggplot2)
library(knitr)
df <- jsonlite::fromJSON("../mojLawSplitJSON/index.json", flatten = T) %>% tbl_df()
mutate_update_entry <- function(entry) {
ifelse(is.null(entry), "" , str_c(entry, collapse = ","))
}
paste_updates_and_lastupdate <- function(entry){
ifelse(is.na(entry), lastUpdate, str_c(entry, lastUpdate,sep = ","))
}
df2 <- df %>%
mutate(updates = lapply(updates, mutate_update_entry)) %>%
rowwise() %>%
mutate(
updates = ifelse(
updates == "",
lastUpdate,
str_c(updates, lastUpdate, sep = ",")
)
)
df3 <- df2 %>%
select(PCode, updates) %>%
transform(updates = str_split(updates, ",")) %>%
unnest(updates)
df4 <- df3 %>%
mutate(updates = ymd(updates)) %>%
mutate(year = year(updates))
## Warning: 3 failed to parse.
df4$year %>% hist
df4 %>% count(PCode, sort = T) %>% top_n(10) %>% left_join(df, by = "PCode") %>%
select(name, n) %>% kable()
## Selecting by n
| name | n |
|---|---|
| 商業團體分業標準 | 61 |
| 道路交通安全規則 | 53 |
| 建築技術規則建築設計施工編 | 44 |
| 農藥殘留容許量標準 | 41 |
| 證券商管理規則 | 33 |
| 汽車運輸業管理規則 | 31 |
| 固定通信業務管理規則 | 30 |
| 違反道路交通管理事件統一裁罰基準及處理細則 | 29 |
| 食品添加物使用範圍及限量暨規格標準 | 27 |
| 工業及礦業團體分業標準 | 26 |
df4 %>% count(year) %>%
filter(year >1992) %>%
ggplot(aes(x = year, y = n)) + geom_bar(stat = "identity")
base_year <- 2005
age_2005 <- df4 %>% filter(year <= base_year) %>%
group_by(PCode) %>%
summarize(lastUpdated = max(year)) %>%
mutate(age = base_year - lastUpdated)
age_2005$age %>% hist()
未完待續…