I have a function that makes a table, but the column and rows need to be switched. I was hoping to just add something to the end of my function that would just invert the two.
I thought I would be able to use (.,t, df_name), but I realize that using this at the end didn't work because at that point it's no longer a data frame. Would my best option then be to just do this at the data frame level and rewrite all references i.e. filters, renaming, etc. that are currently calling by column to call by row instead after I transpose?
Here's a glimpse of what it currently is:
total_stats = submarket_stats %>%
rename(`Direct Vacant SF` = `Vacant SF - Direct`,
`Sublease Vacant SF` = `Vacant SF - Sublease`,
`Overall Vacant SF` = `Vacant SF - Total`) %>%
replace_na(list(District = "Unspecified")) %>%
arrange(Market, Submarket) %>%
mutate(across(c(`Direct Vacancy Rate`, `Overall Vacancy Rate`, `Overall Availability Rate`), scales::percent, accuracy = .1),
across(c(`Property Count`, NRA,
`Direct Vacant SF`, `Sublease Vacant SF`, `Overall Vacant SF`,
`Overall Available SF`),
scales::dollar, accuracy = 1, style_negative="parens", prefix=""),
across(any_of(c("Full Service Gross Asking Rate", "Lease Rate")),
scales::dollar)) %>%
select(Submarket, all_of(col_order)) %>%
replace_na(list(`Full Service Gross Asking Rate` = "-"))
table_rows = if(property_type == "Industrial") 23 else 20
table_breaks = ((1:floor(nrow(total_stats)/table_rows))*table_rows)+1
split(total_stats, cumsum(1:nrow(total_stats) %in% table_breaks))
# where i wanted to just switch column and rows