Here, we wanted to order rows based on the percentage value (highest to lowest) in a column (in shiny, the cells of this column display both a count and a percentage).
I created a sort key copying over the value in estimate_value given that estimate_value represented a percentage (rather than a count). The values in estimate_value were stored as characters because of the use of "-" in some cases, so we converted to numeric. We then arranged based on this key and then dropped the column!
lsc_summarised_result <- lsc_summarised_result %>%
omopgenerics::splitGroup() %>%
dplyr::mutate(sort_key = case_when(
(estimate_type == "percentage" & estimate_name == "percentage" & estimate_value != "-") ~ as.numeric(estimate_value),
TRUE ~ NA # explicitly assign everything else NA
)) %>%
dplyr::arrange(cdm_name, desc(sort_key)) %>%
dplyr::select(-sort_key) %>% # drop sorting column
omopgenerics::uniteGroup(cols = c("cohort_name")) # unite once more
As with #54, omopgenerics::splitGroup() and omopgenerics::uniteGroup were used to maintain the integrity of the summarised_results object
Here, we wanted to order rows based on the percentage value (highest to lowest) in a column (in shiny, the cells of this column display both a count and a percentage).
I created a sort key copying over the value in estimate_value given that estimate_value represented a percentage (rather than a count). The values in estimate_value were stored as characters because of the use of "-" in some cases, so we converted to numeric. We then arranged based on this key and then dropped the column!
As with #54,
omopgenerics::splitGroup()andomopgenerics::uniteGroupwere used to maintain the integrity of the summarised_results object