Skip to content

Commit

Permalink
fixed #39
Browse files Browse the repository at this point in the history
  • Loading branch information
xinyigua committed Aug 22, 2023
1 parent 970eeeb commit 369e0fd
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions R/regioncode.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,10 @@ regioncode <- function(data_input,
}
)


# Using the Municipal codes for within region codes
if (zhixiashi) {

region_zhixiashi <- region_data %>%
filter(zhixiashi)

Expand All @@ -276,39 +278,53 @@ regioncode <- function(data_input,
region_code <- region_zhixiashi %>%
select(ends_with("_code"))

region_rank <- region_zhixiashi %>%
select(ends_with("_rank"))
region_remain <- region_zhixiashi %>%
select(-ends_with("_code"),
-ends_with("_sname"),
-ends_with("_name"),
-ends_with("language"),
-ends_with("_all"),
-ends_with("_nickname"),
-'dia_sub_group',
-'freq')

# replacing the prefectural names and codes with provincial names and codes
region_sname2 <-
replicate(ncol(region_sname), region_zhixiashi$prov_sname) %>%
as.data.frame()
names(region_sname2) <- names(region_sname)

region_name2 <-
replicate(ncol(region_name), region_zhixiashi$prov_name) %>%
as.data.frame()
names(region_name2) <- names(region_name)

region_sname2 <-
replicate(ncol(region_name), region_zhixiashi$prov_name) %>%
as.data.frame()
names(region_sname2) <- names(region_sname2)

region_code2 <-
replicate(ncol(region_code), region_zhixiashi$prov_code) %>%
as.data.frame()
names(region_code2) <- names(region_code)


region_zhixiashi <-
bind_cols(region_sname2, region_name2, region_code2,region_rank)
cbind(region_name2, region_code2,region_sname2,region_remain)
region_zhixiashi <- distinct(
region_zhixiashi[, order(colnames(region_zhixiashi))])
region_zhixiashi <- region_zhixiashi %>%
select('1986_code':prov_scode)

region_province <- region_data %>%
filter(!zhixiashi)
region_province <- distinct(
region_province[, order(colnames(region_province))])

region_data <- bind_rows(region_zhixiashi, region_province)
select(region_data,
-ends_with("language"),
-ends_with("_all"),
-ends_with("_nickname"),
-dia_sub_group,
-freq)
)
region_province <- region_province[, order(colnames(region_province))]


region_data<- bind_rows(region_zhixiashi, region_province)
}
}
}
Expand Down

0 comments on commit 369e0fd

Please sign in to comment.