Skip to content

Commit

Permalink
prep census_tracts_aggreg_2022_prelim, col classes
Browse files Browse the repository at this point in the history
  • Loading branch information
rafapereirabr committed Mar 28, 2024
1 parent f192664 commit 1282415
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ BugReports: https://github.com/ipeaGIT/censobr/issues
Depends:
R (>= 4.0)
Imports:
arrow,
arrow (>= 15.0.1),
checkmate,
dplyr,
httr (>= 1.4.1),
Expand Down
21 changes: 16 additions & 5 deletions data_prep/R/census_tracts_aggreg_2022_prelim.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ df[, CD_SETOR := gsub("P","", CD_SETOR)]
head(df)


# make all columns as character
df <- mutate(df, across(everything(), as.character))

# rename columns
names(df) <- toupper(names(df))

df2 <- dplyr::rename(df,
df2 <- dplyr::select(df,
code_tract = CD_SETOR,
code_muni = CD_MUN,
name_muni = NM_MUN,
Expand All @@ -38,17 +36,30 @@ df2 <- dplyr::rename(df,
name_intermediate = NM_RGINT,
code_region = CD_REGIAO,
name_region = NM_REGIAO,
V0001 = V0001,
V0002 = V0002,
V0003 = V0003,
V0004 = V0004,
V0005 = V0005,
V0006 = V0006,
V0007 = V0007,
area_km2 = AREA_KM2
)
head(df2)

# make all columns as character
character_cols <- names(df2)[names(df2) %like% 'code_|name_']
df2 <- mutate(df2, across(everything(character_cols), as.character))

sapply(df2, class)


# save
dir.create('./data/tracts/2022/', recursive = T)

dest_file <- paste0('2022_tracts_Preliminares.parquet')
arrow::write_parquet(df2, paste0('./data/tracts/2022/', dest_file))

arrow::write_parquet(df2, 'd2.parquet')



0 comments on commit 1282415

Please sign in to comment.