#' get_freq
#'
#' Returns the relative frequency of a qualitative variable
#'
#' @param var qualitative variable
#' @param df_1 data frame
#'
#' @return data frame of relative frequencies
#' @export
#' @import dplyr
#'
#' @examples
#' library(igfuns)
#' data(bregs)
#' get_freq(bregs, vh)
get_freq <- function(df_1, var) {
freq <- NULL
df_1 %>%
select(!!enexpr(var)) %>%
group_by(!!enexpr(var)) %>%
summarise(n=n()) %>%
mutate(freq=n/sum(n)*100) %>%
arrange(desc(freq))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.