|
1 | | -} |
2 | | -df <- df %>% select(-year, -population) |
3 | | -return(df) |
4 | | -} |
5 | | -dfs <- map(2020:2022, ~new %>% |
6 | | -filter(year == .x) %>% |
7 | | -new_cityranking(., .x)) |
8 | | -View(dfs) |
9 | | -str(new) |
10 | | -new_cityranking <- function(df, year) { |
11 | | -year_cityranking <- paste0(year, "_cityranking") |
12 | | -if (year %in% 1986:2013) { |
13 | | -df[[year_cityranking]] <- case_when( |
14 | | -df$population > 100 ~ "特大城市", |
15 | | -df$population > 50 & df$population <= 100 ~ "大城市", |
16 | | -df$population > 20 & df$population <= 50 ~ "中等城市", |
17 | | -df$population <= 20 ~ "小城市", |
18 | | -TRUE ~ NA_character_ |
19 | | -) |
20 | | -} else if (year > 2013) { |
21 | | -df[[year_cityranking]] <- case_when( |
22 | | -df$population > 1000 ~ "超大城市", |
23 | | -df$population > 500 & df$population <= 1000 ~ "特大城市", |
24 | | -df$population > 300 & df$population <= 500 ~ "I型大城市", |
25 | | -df$population > 100 & df$population <= 300 ~ "II型大城市", |
26 | | -df$population > 50 & df$population <= 100 ~ "中等城市", |
27 | | -df$population > 20 & df$population <= 50 ~ "I型小城市", |
28 | | -df$population <= 20 ~ "II型小城市", |
29 | | -TRUE ~ NA_character_ |
30 | | -) |
31 | | -} |
32 | | -df <- df %>% select(-year, -population) |
33 | | -return(df) |
34 | | -} |
35 | | -dfs <- map(2020:2022, ~new %>% |
36 | | -filter(year == .x) %>% |
37 | | -new_cityranking(., .x)) |
38 | | -View(dfs) |
39 | | -new_cityranking<- reduce(dfs, full_join, by = c("code")) |
40 | | -View(new_cityranking) |
41 | | -new_cityranking <- new_cityranking %>% |
42 | | -select(-contains("地市级")) |
43 | | -View(new_cityranking) |
44 | | -new_cityranking <- new_cityranking %>% |
45 | | -select(-contains("地级")) |
46 | | -View(new_cityranking) |
47 | | -library(readxl) |
48 | | -region_data <- read_excel("region_data.xlsx") |
49 | | -View(region_data) |
50 | | -View(new_cityranking) |
51 | | -region_data <- region_data %>% |
52 | | -mutate(join_key = case_when( |
53 | | -zhixiashi == TRUE ~ prov_code, |
54 | | -zhixiashi != TRUE ~ `2022_code` |
55 | | -)) |
56 | | -View(region_data) |
57 | | -region_data <- region_data %>% |
58 | | -left_join(new_cityranking, by = c("join_key" = "code")) %>% |
59 | | -select(-"join_key") |
60 | | -View(new) |
61 | | -View(new_cityranking) |
62 | | -View(new_cityranking) |
63 | | -any(duplicated(new_cityranking$code)) |
64 | | -duplicated_codes <- new_cityranking$code[duplicated(new_cityranking$code)] |
65 | | -unique(duplicated_codes) |
66 | | -new<- import("~/Desktop/全国各市城镇人口构成.xlsx") |
67 | 1 | new <- new %>% |
68 | 2 | mutate(population = as.numeric(population)) %>% |
69 | 3 | arrange(code, year) |
@@ -510,3 +444,69 @@ library(dplyr) |
510 | 444 | library(regioncode) |
511 | 445 | data("corruption") |
512 | 446 | force(corruption) |
| 447 | +load("~/Develop/regioncode/data/corruption.rda") |
| 448 | +View(corruption) |
| 449 | +View(corruption) |
| 450 | +load("~/Develop/regioncode/dev/corruption_data.rda") |
| 451 | +View(vignette_data) |
| 452 | +load("~/Develop/regioncode/dev/vignette_data.rda") |
| 453 | +load("~/Develop/regioncode/dev/corruption_data.rda") |
| 454 | +load("~/Develop/regioncode/data/corruption.rda") |
| 455 | +load("~/Develop/regioncode/data/corruption.rda") |
| 456 | +load("~/Develop/regioncode/data/corruption.rda") |
| 457 | +View(corruption) |
| 458 | +load("~/Develop/regioncode/dev/regioncode/corruption.rda") |
| 459 | +load("~/Develop/regioncode/dev/regioncode/corruption.rda") |
| 460 | +View(corruption) |
| 461 | +load("~/Develop/regioncode/dev/regioncode/corruption.rda") |
| 462 | +View(corruption) |
| 463 | +load("~/Develop/regioncode/dev/regioncode/.RData") |
| 464 | +load("~/Develop/regioncode/dev/regioncode/.RData") |
| 465 | +vignette <- readRDS("~/Develop/regioncode/Meta/vignette.rds") |
| 466 | +View(vignette) |
| 467 | +load("~/Develop/regioncode/R/sysdata.rda") |
| 468 | +View(region_data) |
| 469 | +load("~/Develop/regioncode/R/sysdata.rda") |
| 470 | +load("~/Develop/regioncode/dev/vignette_data.rda") |
| 471 | +View(vignette_data) |
| 472 | +load("~/Develop/regioncode/dev/vignette_data.rda") |
| 473 | +View(vignette_data) |
| 474 | +load("~/Develop/regioncode/dev/corruption_data.rda") |
| 475 | +View(vignette_data) |
| 476 | +View(vignette_data) |
| 477 | +load("dev/vignette_data.rda") |
| 478 | +load("~/Develop/regioncode/dev/corruption_data.rda") |
| 479 | +load("~/Develop/regioncode/dev/corruption_data.rda") |
| 480 | +str(vignette_data) |
| 481 | +library(dplyr) |
| 482 | +load("~/Develop/regioncode/dev/corruption_data.rda") |
| 483 | +str(corruption_data) |
| 484 | +str(corruption_data.rda) |
| 485 | +load("~/Develop/regioncode/dev/corruption_data.rda") |
| 486 | +View(vignette_data) |
| 487 | +library(dplyr) |
| 488 | +load("~/Develop/regioncode/dev/corruption_data.rda") |
| 489 | +str(vignette_data) |
| 490 | +vignette_data_modified <- vignette_data %>% |
| 491 | +mutate( |
| 492 | +prefecture_id = ifelse(Year >= 2015 & prefecture_id == 469003, 460400, prefecture_id), |
| 493 | +county_id = ifelse(Year >= 2015 & county_id == 469003, 460400, county_id) |
| 494 | +) |
| 495 | +cat("修改后 - 2015年及以后prefecture_id的分布:\n") |
| 496 | +vignette_data_modified %>% |
| 497 | +filter(Year >= 2015) %>% |
| 498 | +count(prefecture_id) %>% |
| 499 | +print() |
| 500 | +vignette_data_modified <- vignette_data %>% |
| 501 | +mutate( |
| 502 | +prefecture_id = ifelse(as.numeric(Year) >= 2015 & prefecture_id == 469003, 460400, prefecture_id), |
| 503 | +county_id = ifelse(as.numeric(Year) >= 2015 & county_id == 469003, 460400, county_id) |
| 504 | +) |
| 505 | +dplyr::last_dplyr_warnings() |
| 506 | +load("~/Develop/regioncode/dev/corruption_data.rda") |
| 507 | +vignette_data$Year <- as.numeric(vignette_data$Year) |
| 508 | +vignette_data$prefecture_id[vignette_data$Year >= 2015 & vignette_data$prefecture_id == 469003] <- 460400 |
| 509 | +vignette_data$county_id[vignette_data$Year >= 2015 & vignette_data$county_id == 469003] <- 460400 |
| 510 | +save(vignette_data, file = "~/Develop/regioncode/dev/corruption_data.rda") |
| 511 | +load("~/Develop/regioncode/dev/corruption_data.rda") |
| 512 | +View(vignette_data) |
0 commit comments