Computes profiles (frequencies or percentages) for subgroups of observations defined by the levels of a categorical variable.

profiles(X, y, weights = NULL, stat = "cprop",
 mar = TRUE, digits = 1)

Arguments

X

data frame. The variables which are described in the profiles. There should be only factors.

y

factor. The categorical variable which defines subgroups of observations whose profiles will be computed.

weights

numeric vector of weights. If NULL (default), uniform weights (i.e. all equal to 1) are used.

stat

character. Whether to compute frequencies ("freq"), percentages ("prop"), row percentages ("rprop") or column percentages ("cprop", default).

mar

logical, indicating whether to compute margins. Default is TRUE.

digits

numeric. Number of digits. Default is 1.

Value

A data frame with profiles in columns

Author

Nicolas Robette

Examples

data(Movies)
profiles(Movies[,c(2,4,5)], Movies$Country)
#>                   Europe France Other  USA total
#> Genre.Action        19.4    9.8  23.1 29.0  16.5
#> Genre.Animation      2.8    3.0   0.0  8.8   4.6
#> Genre.Other          5.6    2.1   0.0  3.0   2.6
#> Genre.ComDram       13.9   18.2  11.5  8.8  14.9
#> Genre.Comedy        22.2   23.8  15.4 19.5  22.2
#> Genre.Documentary    1.4   12.1   3.8  0.7   7.7
#> Genre.Drama         25.0   29.6  34.6 11.8  24.1
#> Genre.Horror         4.2    0.2   3.8  6.7   2.5
#> Genre.SciFi          5.6    1.3   7.7 11.8   4.9
#> ArtHouse.No         54.2   35.0  23.1 86.5  51.4
#> ArtHouse.Yes        45.8   65.0  76.9 13.5  48.6
#> Festival.No         90.3   91.9  92.3 93.6  92.3
#> Festival.Yes         9.7    8.1   7.7  6.4   7.7