Top_frac Inverse

Getting to the bottom half

-Chat-GPT, DPLYR
Author

Kevn Gilds, MPA

Published

2023-12-30

I had a graph in a Shiny Application that had too many values and the values were getting scrunched up. I determined to add a tab panel and display multiple views.

I used top_frac function from the dplyr 📦.

top_sites <- reactive({
        sites_program() %>%
        dplyr::group_by(time) %>%
        dplyr::count(site)%>%
        dplyr::top_frac(.5)
})

My next dilemma was getting the bottom half. I used Chat-GPT and here is the transcript.

I was able to take the example and apply to my data set. This would have taken me hours to figure our prior to this assistance.

bottom_sites <- reactive({
      bottom_frac <- 0.5
      result <- sites_program() %>%
        dplyr::group_by(time) %>%
        dplyr::count(site)%>%
        arrange(n) %>%
        slice(1:floor(n() * bottom_frac))
      
    })

About

Kevin is a nonprofit data professional operating out of Lakeland, Florida.
My expertise is helping nonprofits collect, manage and analyze their program data.