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        14.6    7.3  17.3 21.7  12.4
#> Genre.Animation      2.1    2.2   0.0  6.6   3.5
#> Genre.Other          4.2    1.6   0.0  2.3   2.0
#> Genre.ComDram       10.4   13.6   8.7  6.6  11.2
#> Genre.Comedy        16.7   17.9  11.5 14.6  16.7
#> Genre.Documentary    1.0    9.0   2.9  0.5   5.8
#> Genre.Drama         18.8   22.2  26.0  8.8  18.1
#> Genre.Horror         3.1    0.1   2.9  5.1   1.9
#> Genre.SciFi          4.2    1.0   5.8  8.8   3.7
#> ArtHouse.No         40.6   26.3  17.3 64.9  38.6
#> ArtHouse.Yes        34.4   48.7  57.7 10.1  36.4
#> Festival.No         67.7   68.9  69.2 70.2  69.2
#> Festival.Yes         7.3    6.1   5.8  4.8   5.8