R/grouped_central.R
grouped.mean.Rd
Calculate mean for grouped data using frequency, either percent or counts. The function will split each character element in x and find the midpoint of its lower and upper bounds.
grouped.mean(x, freq, freq_format = "count", na.rm = FALSE)
character vector of categories or ranges
numeric vector containing category counts or percentages
intended freq format. Use percent if you want freq converted to percent
remove NA from calculations
NA
a numeric vector of length 1L
age <- c("0-4","5-9","10-14", "15-19","20-24", "25-29","30-34", "35-39","40-44", "45-49","50-54", "55-59","60-64", "65-69","70-74", "75-79","80-84", "85-89") freq <- seq(5400, 300, by = -300) grouped.mean(age,freq, freq_format = "percent") #> [1] 30.33333