Skip to contents

A wrapper to aggregate that gives a wide view of results

Usage

aggregate_wide(x, what, fun = sum)

Arguments

x

data.frame

what

vector of length

fun

function

Value

A matrix of result

Examples

x = data.frame(
    gender = sample(c("H", "F"), 20, replace = TRUE),
    region = sample(c("east", "west", "south", "north"), 20, replace = TRUE),
    wealth = round(runif(20) * 10000),
    size = round(runif(20) * 50 + 150)
)
aggregate_wide(x)
#>    east north south west
#> F 21186 18105 13190 7581
#> H 26426  8189  9063 6998
aggregate_wide(x, c("region", "gender", "wealth"))
#>           F     H
#> east  21186 26426
#> north 18105  8189
#> south 13190  9063
#> west   7581  6998
aggregate_wide(x, c("region", "gender", "size"))
#>         F   H
#> east  720 894
#> north 539 186
#> south 529 165
#> west  377 193
aggregate_wide(x, c("region", "gender", "wealth"), mean)
#>              F      H
#> east  5296.500 5285.2
#> north 6035.000 8189.0
#> south 4396.667 9063.0
#> west  3790.500 6998.0