# gather income groups as columns, into 1 single colum
table2a <- table2
# replace "na" with 0 in number columns
table2a[, 3:8][is.na(table2a[, 3:8] ) ] = 0
# tidy Table 2 data
tb2 <- table2a %>%
rename(State = `State/ Territory1`) %>%
filter(State != "Overseas or unknown") %>%
mutate(Postcode2=ifelse(str_length(as.numeric(Postcode))<=3,str_c("0",Postcode),Postcode)) %>%
rename(postcode = Postcode2) %>%
rename(`f. $180,001 or more` = `f. $80,001 or more`) %>%
gather(`a. $18,200 or less`:`f. $180,001 or more`,
key = "Inc Group", value = "Inc Group No")
## Warning in stri_length(string): NAs introduced by coercion
# remove extra Postcode column
tb2$Postcode <- NULL
Lets view Income Groups by Population, and Income Groups by State: