I am using the url link to download this dataset:
https://files.hawaii.gov/dbedt/census/census_2020/data/redistricting/PLtable1_2020-county.xlsx
So in R I am coding it as:
url_dbedt_dicennial <- "https://files.hawaii.gov/dbedt/census/census_2020/data/redistricting/PLtable1_2020-county.xlsx"
# download the xls to a temporary file
temp <- tempfile(fileext = ".xlsx")
download.file(url = url_dbedt_dicennial, destfile = temp, mode = "wb")
# data from dbedt dicennial (look at each step to understand)
data_in_dbedt_dicennial <- temp %>%
readxl::read_excel(
range = cellranger::as.cell_limits("A6:H15"),) %>%
t() %>%
The generated output is the following:
What I am struggling right now after transpose is to how relabel the columns as "time", "HI", "HON", "HAW", "KAU", "MAU" and then to eliminate V1, V3, V8, and V9. I know I can eliminate columns manually one-by-one but there is a clever way of doing it? County should be relabeled as time.
Eventually I want to use the mutate function for the time variable, that is,
mutate(time)
and convert the data into time series with
tsbox::ts_long()
State of Hawaii should be labeled as "HI", Hawaii County as "HAW", City and County of Honolulu as "HON", Kauai County as "KAU", and Maui County 1/ as "MAU"