Description Usage Arguments Value Author(s) References Examples
View source: R/GroupedMedian.R
Calculates the median of already grouped data given the interval ranges and the frequencies of each group.
1 | GroupedMedian(frequencies, intervals, sep = NULL, trim = NULL)
|
frequencies |
A vector of frequencies. |
intervals |
A 2-row |
sep |
Optional. If the |
trim |
Characters to trim from the vector before splitting. For
example, if you are doing this on the output of |
A single numeric value representing the grouped median.
Ananda Mahto
http://stackoverflow.com/a/18931054/1270695
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | mydf <- structure(list(salary = c("1500-1600", "1600-1700", "1700-1800",
"1800-1900", "1900-2000", "2000-2100", "2100-2200", "2200-2300",
"2300-2400", "2400-2500"), number = c(110L, 180L, 320L, 460L,
850L, 250L, 130L, 70L, 20L, 10L)), .Names = c("salary", "number"),
class = "data.frame", row.names = c(NA, -10L))
mydf
GroupedMedian(frequencies = mydf$number, intervals = mydf$salary, sep = "-")
## Example with intervals manually specified
X <- rbind(c(1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400),
c(1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500))
GroupedMedian(mydf$number, X)
set.seed(1)
x <- sample(100, 100, replace = TRUE)
y <- data.frame(table(cut(x, 10)))
GroupedMedian(y$Freq, y$Var1, sep = ",", trim = "cut")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.