#' Calculate mean value in adm. bounds
#'
#' Calculates the mean value by administraive boundaries
#' @param .table Data table
#' @param .var Variable name inputted as symbol
#' @param .name String specifying variable name
#' @param .admbounds String specifying administrative codes
#'
#' @return Tibble with mean value by administrative code
#' @export
#' @examples
#' meanCalc(data[['building']], sym('dm_grade'), 'dm_grade', 'ward')
#'
meanCalc <- function(.table, .var, .name, .admbounds) {
mean_var <- quo(!!.var)
means <- .table %>%
group_by_(.admbounds) %>%
summarize(m = mean(!!mean_var, na.rm=TRUE))
colnames(means) = c(.admbounds,paste(.name,'m',sep=''))
return(means)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.