#' Cette fonction permet de faire des tris à plats pondérés
#'
#' @param lst output tris croisés
#' @param x liste des variables
#' @export
#' @examples
#' lst = sapply(seq_along(dat), function(x) table.freq.weighted(dat, x, "pond"), simplify = F)
# Fonction de tri à plat pondéré
table.freq.weighted = function(data, var, pond){
# Usefull package
require(questionr)
# Select columns
dat = data %>%
select_(.dots = c(var, pond))
# Levels
lev = levels(dat[[1]])
# Table pondérées
tw1 = round(wtd.table(dat[[1]], weights = dat[[2]]))
# Prop table
twp1 = prop.table(tw1)
# Collect results
res = tibble(
"modality" = lev,
"weighted_frequency" = tw1,
"weighted_percentage" = twp1
)
# Output
return(res)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.