This function returns a frequency table of labelled vectors, as data frame.

frq(x, ..., sort.frq = c("none", "asc", "desc"), weights = NULL,
  auto.grp = NULL, show.strings = TRUE, show.na = TRUE,
  grp.strings = NULL, out = c("txt", "viewer", "browser"),
  title = NULL, encoding = "UTF-8", file = NULL)

Arguments

x

A vector or a data frame. May also be a grouped data frame (see 'Note' and 'Examples').

...

Optional, unquoted names of variables that should be selected for further processing. Required, if x is a data frame (and no vector) and only selected variables from x should be processed. You may also use functions like : or tidyselect's select_helpers. See 'Examples' or package-vignette.

sort.frq

Determines whether categories should be sorted according to their frequencies or not. Default is "none", so categories are not sorted by frequency. Use "asc" or "desc" for sorting categories ascending or descending order.

weights

Bare name, or name as string, of a variable in x that indicates the vector of weights, which will be applied to weight all observations. Default is NULL, so no weights are used.

auto.grp

Numeric value, indicating the minimum amount of unique values in a variable, at which automatic grouping into smaller units is done (see group_var). Default value for auto.group is NULL, i.e. auto-grouping is off.

show.strings

Logical, if TRUE, frequency tables for character vectors will not be printed. This is useful when printing frequency tables of all variables from a data frame, and due to computational reasons character vectors should not be printed.

show.na

Logical, or "auto". If TRUE, the output always contains information on missing values, even if variables have no missing values. If FALSE, information on missing values are removed from the output. If show.na = "auto", information on missing values is only shown when variables actually have missing values, else it's not shown.

grp.strings

Numeric, if not NULL, groups string values in character vectors, based on their similarity. See group_str and str_find for details on grouping, and their precision-argument to get more details on the distance of strings to be treated as equal.

out

Character vector, indicating whether the results should be printed to console (out = "txt") or as HTML-table in the viewer-pane (out = "viewer") or browser (out = "browser").

title

String, will be used as alternative title to the variable label. If x is a grouped data frame, title must be a vector of same length as groups.

encoding

Character vector, indicating the charset encoding used for variable and value labels. Default is "UTF-8". Only used when out is not "txt".

file

Destination file, if the output should be saved as file. Only used when out is not "txt".

Value

A list of data frames with values, value labels, frequencies, raw, valid and cumulative percentages of x.

Note

x may also be a grouped data frame (see group_by) with up to two grouping variables. Frequency tables are created for each subgroup then.

The print()-method adds a table header with information on the variable label, variable type, total and valid N, and mean and standard deviations. Mean and SD are always printed, even for categorical variables (factors) or character vectors. In this case, values are coerced into numeric vector to calculate the summary statistics.

See also

flat_table for labelled (proportional) tables.

Examples

# simple vector data(efc) frq(efc$e42dep)
#> #> elder's dependency (x) <numeric> #> # total N=908 valid N=901 mean=2.94 sd=0.94 #> #> val label frq raw.prc valid.prc cum.prc #> 1 independent 66 7.27 7.33 7.33 #> 2 slightly dependent 225 24.78 24.97 32.30 #> 3 moderately dependent 306 33.70 33.96 66.26 #> 4 severely dependent 304 33.48 33.74 100.00 #> NA NA 7 0.77 NA NA #>
# with grouped data frames, in a pipe library(dplyr) efc %>% group_by(e16sex, c172code) %>% frq(e16sex, c172code, e42dep)
#> #> elder's gender (e16sex1) <numeric> #> # grouped by: male, low level of education #> # total N=80 valid N=80 mean=1.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 male 80 100 100 100 #> 2 female 0 0 0 100 #> NA NA 0 0 NA NA #> #> #> elder's gender (e16sex1) <numeric> #> # grouped by: male, intermediate level of education #> # total N=156 valid N=156 mean=1.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 male 156 100 100 100 #> 2 female 0 0 0 100 #> NA NA 0 0 NA NA #> #> #> elder's gender (e16sex1) <numeric> #> # grouped by: male, high level of education #> # total N=43 valid N=43 mean=1.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 male 43 100 100 100 #> 2 female 0 0 0 100 #> NA NA 0 0 NA NA #> #> #> elder's gender (e16sex1) <numeric> #> # grouped by: female, low level of education #> # total N=99 valid N=99 mean=2.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 male 0 0 0 0 #> 2 female 99 100 100 100 #> NA NA 0 0 NA NA #> #> #> elder's gender (e16sex1) <numeric> #> # grouped by: female, intermediate level of education #> # total N=350 valid N=350 mean=2.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 male 0 0 0 0 #> 2 female 350 100 100 100 #> NA NA 0 0 NA NA #> #> #> elder's gender (e16sex1) <numeric> #> # grouped by: female, high level of education #> # total N=113 valid N=113 mean=2.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 male 0 0 0 0 #> 2 female 113 100 100 100 #> NA NA 0 0 NA NA #> #> #> carer's level of education (c172code1) <numeric> #> # grouped by: male, low level of education #> # total N=80 valid N=80 mean=1.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 low level of education 80 100 100 100 #> 2 intermediate level of education 0 0 0 100 #> 3 high level of education 0 0 0 100 #> NA NA 0 0 NA NA #> #> #> carer's level of education (c172code1) <numeric> #> # grouped by: male, intermediate level of education #> # total N=156 valid N=156 mean=2.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 low level of education 0 0 0 0 #> 2 intermediate level of education 156 100 100 100 #> 3 high level of education 0 0 0 100 #> NA NA 0 0 NA NA #> #> #> carer's level of education (c172code1) <numeric> #> # grouped by: male, high level of education #> # total N=43 valid N=43 mean=3.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 low level of education 0 0 0 0 #> 2 intermediate level of education 0 0 0 0 #> 3 high level of education 43 100 100 100 #> NA NA 0 0 NA NA #> #> #> carer's level of education (c172code1) <numeric> #> # grouped by: female, low level of education #> # total N=99 valid N=99 mean=1.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 low level of education 99 100 100 100 #> 2 intermediate level of education 0 0 0 100 #> 3 high level of education 0 0 0 100 #> NA NA 0 0 NA NA #> #> #> carer's level of education (c172code1) <numeric> #> # grouped by: female, intermediate level of education #> # total N=350 valid N=350 mean=2.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 low level of education 0 0 0 0 #> 2 intermediate level of education 350 100 100 100 #> 3 high level of education 0 0 0 100 #> NA NA 0 0 NA NA #> #> #> carer's level of education (c172code1) <numeric> #> # grouped by: female, high level of education #> # total N=113 valid N=113 mean=3.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 low level of education 0 0 0 0 #> 2 intermediate level of education 0 0 0 0 #> 3 high level of education 113 100 100 100 #> NA NA 0 0 NA NA #> #> #> elder's gender (e16sex2) <numeric> #> # grouped by: male, low level of education #> # total N=80 valid N=80 mean=1.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 male 80 100 100 100 #> 2 female 0 0 0 100 #> NA NA 0 0 NA NA #> #> #> elder's gender (e16sex2) <numeric> #> # grouped by: male, intermediate level of education #> # total N=156 valid N=156 mean=1.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 male 156 100 100 100 #> 2 female 0 0 0 100 #> NA NA 0 0 NA NA #> #> #> elder's gender (e16sex2) <numeric> #> # grouped by: male, high level of education #> # total N=43 valid N=43 mean=1.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 male 43 100 100 100 #> 2 female 0 0 0 100 #> NA NA 0 0 NA NA #> #> #> elder's gender (e16sex2) <numeric> #> # grouped by: female, low level of education #> # total N=99 valid N=99 mean=2.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 male 0 0 0 0 #> 2 female 99 100 100 100 #> NA NA 0 0 NA NA #> #> #> elder's gender (e16sex2) <numeric> #> # grouped by: female, intermediate level of education #> # total N=350 valid N=350 mean=2.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 male 0 0 0 0 #> 2 female 350 100 100 100 #> NA NA 0 0 NA NA #> #> #> elder's gender (e16sex2) <numeric> #> # grouped by: female, high level of education #> # total N=113 valid N=113 mean=2.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 male 0 0 0 0 #> 2 female 113 100 100 100 #> NA NA 0 0 NA NA #> #> #> carer's level of education (c172code2) <numeric> #> # grouped by: male, low level of education #> # total N=80 valid N=80 mean=1.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 low level of education 80 100 100 100 #> 2 intermediate level of education 0 0 0 100 #> 3 high level of education 0 0 0 100 #> NA NA 0 0 NA NA #> #> #> carer's level of education (c172code2) <numeric> #> # grouped by: male, intermediate level of education #> # total N=156 valid N=156 mean=2.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 low level of education 0 0 0 0 #> 2 intermediate level of education 156 100 100 100 #> 3 high level of education 0 0 0 100 #> NA NA 0 0 NA NA #> #> #> carer's level of education (c172code2) <numeric> #> # grouped by: male, high level of education #> # total N=43 valid N=43 mean=3.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 low level of education 0 0 0 0 #> 2 intermediate level of education 0 0 0 0 #> 3 high level of education 43 100 100 100 #> NA NA 0 0 NA NA #> #> #> carer's level of education (c172code2) <numeric> #> # grouped by: female, low level of education #> # total N=99 valid N=99 mean=1.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 low level of education 99 100 100 100 #> 2 intermediate level of education 0 0 0 100 #> 3 high level of education 0 0 0 100 #> NA NA 0 0 NA NA #> #> #> carer's level of education (c172code2) <numeric> #> # grouped by: female, intermediate level of education #> # total N=350 valid N=350 mean=2.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 low level of education 0 0 0 0 #> 2 intermediate level of education 350 100 100 100 #> 3 high level of education 0 0 0 100 #> NA NA 0 0 NA NA #> #> #> carer's level of education (c172code2) <numeric> #> # grouped by: female, high level of education #> # total N=113 valid N=113 mean=3.00 sd=0.00 #> #> val label frq raw.prc valid.prc cum.prc #> 1 low level of education 0 0 0 0 #> 2 intermediate level of education 0 0 0 0 #> 3 high level of education 113 100 100 100 #> NA NA 0 0 NA NA #> #> #> elder's dependency (e42dep) <numeric> #> # grouped by: male, low level of education #> # total N=80 valid N=80 mean=3.06 sd=0.92 #> #> val label frq raw.prc valid.prc cum.prc #> 1 independent 5 6.25 6.25 6.25 #> 2 slightly dependent 16 20.00 20.00 26.25 #> 3 moderately dependent 28 35.00 35.00 61.25 #> 4 severely dependent 31 38.75 38.75 100.00 #> NA NA 0 0.00 NA NA #> #> #> elder's dependency (e42dep) <numeric> #> # grouped by: male, intermediate level of education #> # total N=156 valid N=156 mean=2.83 sd=0.94 #> #> val label frq raw.prc valid.prc cum.prc #> 1 independent 15 9.62 9.62 9.62 #> 2 slightly dependent 39 25.00 25.00 34.62 #> 3 moderately dependent 59 37.82 37.82 72.44 #> 4 severely dependent 43 27.56 27.56 100.00 #> NA NA 0 0.00 NA NA #> #> #> elder's dependency (e42dep) <numeric> #> # grouped by: male, high level of education #> # total N=43 valid N=43 mean=2.91 sd=0.81 #> #> val label frq raw.prc valid.prc cum.prc #> 1 independent 1 2.33 2.33 2.33 #> 2 slightly dependent 13 30.23 30.23 32.56 #> 3 moderately dependent 18 41.86 41.86 74.42 #> 4 severely dependent 11 25.58 25.58 100.00 #> NA NA 0 0.00 NA NA #> #> #> elder's dependency (e42dep) <numeric> #> # grouped by: female, low level of education #> # total N=99 valid N=99 mean=2.95 sd=0.94 #> #> val label frq raw.prc valid.prc cum.prc #> 1 independent 7 7.07 7.07 7.07 #> 2 slightly dependent 25 25.25 25.25 32.32 #> 3 moderately dependent 33 33.33 33.33 65.66 #> 4 severely dependent 34 34.34 34.34 100.00 #> NA NA 0 0.00 NA NA #> #> #> elder's dependency (e42dep) <numeric> #> # grouped by: female, intermediate level of education #> # total N=350 valid N=350 mean=2.90 sd=0.98 #> #> val label frq raw.prc valid.prc cum.prc #> 1 independent 30 8.57 8.57 8.57 #> 2 slightly dependent 96 27.43 27.43 36.00 #> 3 moderately dependent 104 29.71 29.71 65.71 #> 4 severely dependent 120 34.29 34.29 100.00 #> NA NA 0 0.00 NA NA #> #> #> elder's dependency (e42dep) <numeric> #> # grouped by: female, high level of education #> # total N=113 valid N=113 mean=3.04 sd=0.85 #> #> val label frq raw.prc valid.prc cum.prc #> 1 independent 4 3.54 3.54 3.54 #> 2 slightly dependent 26 23.01 23.01 26.55 #> 3 moderately dependent 44 38.94 38.94 65.49 #> 4 severely dependent 39 34.51 34.51 100.00 #> NA NA 0 0.00 NA NA #>
# with select-helpers: all variables from the COPE-Index # (which all have a "cop" in their name) frq(efc, contains("cop"))
#> #> do you feel you cope well as caregiver? (c82cop1) <numeric> #> # total N=908 valid N=901 mean=3.12 sd=0.58 #> #> val label frq raw.prc valid.prc cum.prc #> 1 never 3 0.33 0.33 0.33 #> 2 sometimes 97 10.68 10.77 11.10 #> 3 often 591 65.09 65.59 76.69 #> 4 always 210 23.13 23.31 100.00 #> NA NA 7 0.77 NA NA #> #> #> do you find caregiving too demanding? (c83cop2) <numeric> #> # total N=908 valid N=902 mean=2.02 sd=0.72 #> #> val label frq raw.prc valid.prc cum.prc #> 1 Never 186 20.48 20.62 20.62 #> 2 Sometimes 547 60.24 60.64 81.26 #> 3 Often 130 14.32 14.41 95.68 #> 4 Always 39 4.30 4.32 100.00 #> NA NA 6 0.66 NA NA #> #> #> does caregiving cause difficulties in your relationship with your friends? (c84cop3) <numeric> #> # total N=908 valid N=902 mean=1.63 sd=0.87 #> #> val label frq raw.prc valid.prc cum.prc #> 1 Never 516 56.83 57.21 57.21 #> 2 Sometimes 252 27.75 27.94 85.14 #> 3 Often 82 9.03 9.09 94.24 #> 4 Always 52 5.73 5.76 100.00 #> NA NA 6 0.66 NA NA #> #> #> does caregiving have negative effect on your physical health? (c85cop4) <numeric> #> # total N=908 valid N=898 mean=1.77 sd=0.87 #> #> val label frq raw.prc valid.prc cum.prc #> 1 Never 409 45.04 45.55 45.55 #> 2 Sometimes 346 38.11 38.53 84.08 #> 3 Often 85 9.36 9.47 93.54 #> 4 Always 58 6.39 6.46 100.00 #> NA NA 10 1.10 NA NA #> #> #> does caregiving cause difficulties in your relationship with your family? (c86cop5) <numeric> #> # total N=908 valid N=902 mean=1.39 sd=0.67 #> #> val label frq raw.prc valid.prc cum.prc #> 1 Never 626 68.94 69.40 69.40 #> 2 Sometimes 211 23.24 23.39 92.79 #> 3 Often 50 5.51 5.54 98.34 #> 4 Always 15 1.65 1.66 100.00 #> NA NA 6 0.66 NA NA #> #> #> does caregiving cause financial difficulties? (c87cop6) <numeric> #> # total N=908 valid N=900 mean=1.29 sd=0.64 #> #> val label frq raw.prc valid.prc cum.prc #> 1 Never 713 78.52 79.22 79.22 #> 2 Sometimes 131 14.43 14.56 93.78 #> 3 Often 39 4.30 4.33 98.11 #> 4 Always 17 1.87 1.89 100.00 #> NA NA 8 0.88 NA NA #> #> #> do you feel trapped in your role as caregiver? (c88cop7) <numeric> #> # total N=908 valid N=900 mean=1.92 sd=0.91 #> #> val label frq raw.prc valid.prc cum.prc #> 1 Never 336 37.00 37.33 37.33 #> 2 Sometimes 374 41.19 41.56 78.89 #> 3 Often 113 12.44 12.56 91.44 #> 4 Always 77 8.48 8.56 100.00 #> NA NA 8 0.88 NA NA #> #> #> do you feel supported by friends/neighbours? (c89cop8) <numeric> #> # total N=908 valid N=901 mean=2.16 sd=1.04 #> #> val label frq raw.prc valid.prc cum.prc #> 1 never 313 34.47 34.74 34.74 #> 2 sometimes 237 26.10 26.30 61.04 #> 3 often 241 26.54 26.75 87.79 #> 4 always 110 12.11 12.21 100.00 #> NA NA 7 0.77 NA NA #> #> #> do you feel caregiving worthwhile? (c90cop9) <numeric> #> # total N=908 valid N=888 mean=2.93 sd=0.96 #> #> val label frq raw.prc valid.prc cum.prc #> 1 never 76 8.37 8.56 8.56 #> 2 sometimes 210 23.13 23.65 32.21 #> 3 often 300 33.04 33.78 65.99 #> 4 always 302 33.26 34.01 100.00 #> NA NA 20 2.20 NA NA #>
# all variables from column "c161sex" to column "c175empl" frq(efc, c161sex:c175empl)
#> #> carer's gender (c161sex) <numeric> #> # total N=908 valid N=901 mean=1.76 sd=0.43 #> #> val label frq raw.prc valid.prc cum.prc #> 1 Male 215 23.68 23.86 23.86 #> 2 Female 686 75.55 76.14 100.00 #> NA NA 7 0.77 NA NA #> #> #> carer's level of education (c172code) <numeric> #> # total N=908 valid N=842 mean=1.97 sd=0.63 #> #> val label frq raw.prc valid.prc cum.prc #> 1 low level of education 180 19.82 21.38 21.38 #> 2 intermediate level of education 506 55.73 60.10 81.47 #> 3 high level of education 156 17.18 18.53 100.00 #> NA NA 66 7.27 NA NA #> #> #> are you currently employed? (c175empl) <numeric> #> # total N=908 valid N=902 mean=0.43 sd=0.49 #> #> val label frq raw.prc valid.prc cum.prc #> 0 no 518 57.05 57.43 57.43 #> 1 yes 384 42.29 42.57 100.00 #> NA NA 6 0.66 NA NA #>
# for non-labelled data, variable name is printed, # and "label" column is removed from output data(iris) frq(iris, Species)
#> #> Species <categorical> #> # total N=150 valid N=150 mean=2.00 sd=0.82 #> #> val frq raw.prc valid.prc cum.prc #> setosa 50 33.33 33.33 33.33 #> versicolor 50 33.33 33.33 66.67 #> virginica 50 33.33 33.33 100.00 #> <NA> 0 0.00 NA NA #>
# other expressions than variables (logical conditions) frq(mtcars, cyl ==6)
#> #> cyl == 6 <lgl> #> # total N=32 valid N=32 mean=0.22 sd=0.42 #> #> val frq raw.prc valid.prc cum.prc #> FALSE 25 78.12 78.12 78.12 #> TRUE 7 21.88 21.88 100.00 #> <NA> 0 0.00 NA NA #>
frq(efc, is.na(nur_pst), contains("cop"))
#> #> is.na(nur_pst) <lgl> #> # total N=908 valid N=908 mean=0.46 sd=0.50 #> #> val frq raw.prc valid.prc cum.prc #> FALSE 489 53.85 53.85 53.85 #> TRUE 419 46.15 46.15 100.00 #> <NA> 0 0.00 NA NA #> #> #> do you feel you cope well as caregiver? (c82cop1) <numeric> #> # total N=908 valid N=901 mean=3.12 sd=0.58 #> #> val label frq raw.prc valid.prc cum.prc #> 1 never 3 0.33 0.33 0.33 #> 2 sometimes 97 10.68 10.77 11.10 #> 3 often 591 65.09 65.59 76.69 #> 4 always 210 23.13 23.31 100.00 #> NA NA 7 0.77 NA NA #> #> #> do you find caregiving too demanding? (c83cop2) <numeric> #> # total N=908 valid N=902 mean=2.02 sd=0.72 #> #> val label frq raw.prc valid.prc cum.prc #> 1 Never 186 20.48 20.62 20.62 #> 2 Sometimes 547 60.24 60.64 81.26 #> 3 Often 130 14.32 14.41 95.68 #> 4 Always 39 4.30 4.32 100.00 #> NA NA 6 0.66 NA NA #> #> #> does caregiving cause difficulties in your relationship with your friends? (c84cop3) <numeric> #> # total N=908 valid N=902 mean=1.63 sd=0.87 #> #> val label frq raw.prc valid.prc cum.prc #> 1 Never 516 56.83 57.21 57.21 #> 2 Sometimes 252 27.75 27.94 85.14 #> 3 Often 82 9.03 9.09 94.24 #> 4 Always 52 5.73 5.76 100.00 #> NA NA 6 0.66 NA NA #> #> #> does caregiving have negative effect on your physical health? (c85cop4) <numeric> #> # total N=908 valid N=898 mean=1.77 sd=0.87 #> #> val label frq raw.prc valid.prc cum.prc #> 1 Never 409 45.04 45.55 45.55 #> 2 Sometimes 346 38.11 38.53 84.08 #> 3 Often 85 9.36 9.47 93.54 #> 4 Always 58 6.39 6.46 100.00 #> NA NA 10 1.10 NA NA #> #> #> does caregiving cause difficulties in your relationship with your family? (c86cop5) <numeric> #> # total N=908 valid N=902 mean=1.39 sd=0.67 #> #> val label frq raw.prc valid.prc cum.prc #> 1 Never 626 68.94 69.40 69.40 #> 2 Sometimes 211 23.24 23.39 92.79 #> 3 Often 50 5.51 5.54 98.34 #> 4 Always 15 1.65 1.66 100.00 #> NA NA 6 0.66 NA NA #> #> #> does caregiving cause financial difficulties? (c87cop6) <numeric> #> # total N=908 valid N=900 mean=1.29 sd=0.64 #> #> val label frq raw.prc valid.prc cum.prc #> 1 Never 713 78.52 79.22 79.22 #> 2 Sometimes 131 14.43 14.56 93.78 #> 3 Often 39 4.30 4.33 98.11 #> 4 Always 17 1.87 1.89 100.00 #> NA NA 8 0.88 NA NA #> #> #> do you feel trapped in your role as caregiver? (c88cop7) <numeric> #> # total N=908 valid N=900 mean=1.92 sd=0.91 #> #> val label frq raw.prc valid.prc cum.prc #> 1 Never 336 37.00 37.33 37.33 #> 2 Sometimes 374 41.19 41.56 78.89 #> 3 Often 113 12.44 12.56 91.44 #> 4 Always 77 8.48 8.56 100.00 #> NA NA 8 0.88 NA NA #> #> #> do you feel supported by friends/neighbours? (c89cop8) <numeric> #> # total N=908 valid N=901 mean=2.16 sd=1.04 #> #> val label frq raw.prc valid.prc cum.prc #> 1 never 313 34.47 34.74 34.74 #> 2 sometimes 237 26.10 26.30 61.04 #> 3 often 241 26.54 26.75 87.79 #> 4 always 110 12.11 12.21 100.00 #> NA NA 7 0.77 NA NA #> #> #> do you feel caregiving worthwhile? (c90cop9) <numeric> #> # total N=908 valid N=888 mean=2.93 sd=0.96 #> #> val label frq raw.prc valid.prc cum.prc #> 1 never 76 8.37 8.56 8.56 #> 2 sometimes 210 23.13 23.65 32.21 #> 3 often 300 33.04 33.78 65.99 #> 4 always 302 33.26 34.01 100.00 #> NA NA 20 2.20 NA NA #>
iris %>% frq(starts_with("Petal"), Sepal.Length >5)
#> #> Petal.Length <numeric> #> # total N=150 valid N=150 mean=3.76 sd=1.77 #> #> val frq raw.prc valid.prc cum.prc #> 1 1 0.67 0.67 0.67 #> 1.1 1 0.67 0.67 1.33 #> 1.2 2 1.33 1.33 2.67 #> 1.3 7 4.67 4.67 7.33 #> 1.4 13 8.67 8.67 16.00 #> 1.5 13 8.67 8.67 24.67 #> 1.6 7 4.67 4.67 29.33 #> 1.7 4 2.67 2.67 32.00 #> 1.9 2 1.33 1.33 33.33 #> 3 1 0.67 0.67 34.00 #> 3.3 2 1.33 1.33 35.33 #> 3.5 2 1.33 1.33 36.67 #> 3.6 1 0.67 0.67 37.33 #> 3.7 1 0.67 0.67 38.00 #> 3.8 1 0.67 0.67 38.67 #> 3.9 3 2.00 2.00 40.67 #> 4 5 3.33 3.33 44.00 #> 4.1 3 2.00 2.00 46.00 #> 4.2 4 2.67 2.67 48.67 #> 4.3 2 1.33 1.33 50.00 #> 4.4 4 2.67 2.67 52.67 #> 4.5 8 5.33 5.33 58.00 #> 4.6 3 2.00 2.00 60.00 #> 4.7 5 3.33 3.33 63.33 #> 4.8 4 2.67 2.67 66.00 #> 4.9 5 3.33 3.33 69.33 #> 5 4 2.67 2.67 72.00 #> 5.1 8 5.33 5.33 77.33 #> 5.2 2 1.33 1.33 78.67 #> 5.3 2 1.33 1.33 80.00 #> 5.4 2 1.33 1.33 81.33 #> 5.5 3 2.00 2.00 83.33 #> 5.6 6 4.00 4.00 87.33 #> 5.7 3 2.00 2.00 89.33 #> 5.8 3 2.00 2.00 91.33 #> 5.9 2 1.33 1.33 92.67 #> 6 2 1.33 1.33 94.00 #> 6.1 3 2.00 2.00 96.00 #> 6.3 1 0.67 0.67 96.67 #> 6.4 1 0.67 0.67 97.33 #> 6.6 1 0.67 0.67 98.00 #> 6.7 2 1.33 1.33 99.33 #> 6.9 1 0.67 0.67 100.00 #> <NA> 0 0.00 NA NA #> #> #> Petal.Width <numeric> #> # total N=150 valid N=150 mean=1.20 sd=0.76 #> #> val frq raw.prc valid.prc cum.prc #> 0.1 5 3.33 3.33 3.33 #> 0.2 29 19.33 19.33 22.67 #> 0.3 7 4.67 4.67 27.33 #> 0.4 7 4.67 4.67 32.00 #> 0.5 1 0.67 0.67 32.67 #> 0.6 1 0.67 0.67 33.33 #> 1 7 4.67 4.67 38.00 #> 1.1 3 2.00 2.00 40.00 #> 1.2 5 3.33 3.33 43.33 #> 1.3 13 8.67 8.67 52.00 #> 1.4 8 5.33 5.33 57.33 #> 1.5 12 8.00 8.00 65.33 #> 1.6 4 2.67 2.67 68.00 #> 1.7 2 1.33 1.33 69.33 #> 1.8 12 8.00 8.00 77.33 #> 1.9 5 3.33 3.33 80.67 #> 2 6 4.00 4.00 84.67 #> 2.1 6 4.00 4.00 88.67 #> 2.2 3 2.00 2.00 90.67 #> 2.3 8 5.33 5.33 96.00 #> 2.4 3 2.00 2.00 98.00 #> 2.5 3 2.00 2.00 100.00 #> <NA> 0 0.00 NA NA #> #> #> Sepal.Length > 5 <lgl> #> # total N=150 valid N=150 mean=0.79 sd=0.41 #> #> val frq raw.prc valid.prc cum.prc #> FALSE 32 21.33 21.33 21.33 #> TRUE 118 78.67 78.67 100.00 #> <NA> 0 0.00 NA NA #>
# also works on grouped data frames efc %>% group_by(c172code) %>% frq(is.na(nur_pst))
#> #> is.na(nur_pst) <lgl> #> # grouped by: low level of education #> # total N=180 valid N=180 mean=0.51 sd=0.50 #> #> val frq raw.prc valid.prc cum.prc #> FALSE 89 49.44 49.44 49.44 #> TRUE 91 50.56 50.56 100.00 #> <NA> 0 0.00 NA NA #> #> #> is.na(nur_pst) <lgl> #> # grouped by: intermediate level of education #> # total N=506 valid N=506 mean=0.46 sd=0.50 #> #> val frq raw.prc valid.prc cum.prc #> FALSE 274 54.15 54.15 54.15 #> TRUE 232 45.85 45.85 100.00 #> <NA> 0 0.00 NA NA #> #> #> is.na(nur_pst) <lgl> #> # grouped by: high level of education #> # total N=156 valid N=156 mean=0.47 sd=0.50 #> #> val frq raw.prc valid.prc cum.prc #> FALSE 83 53.21 53.21 53.21 #> TRUE 73 46.79 46.79 100.00 #> <NA> 0 0.00 NA NA #>
# group variables with large range and with weights efc$weights <- abs(rnorm(n = nrow(efc), mean = 1, sd = .5)) frq(efc, c160age, auto.grp = 5, weights = weights)
#> #> carer' age (c160age) <numeric> #> # total N=920 valid N=920 mean=53.85 sd=13.09 #> #> val label frq raw.prc valid.prc cum.prc #> 1 18-32 56 6.09 6.09 6.09 #> 2 33-47 234 25.43 25.43 31.52 #> 3 48-62 380 41.30 41.30 72.83 #> 4 63-77 223 24.24 24.24 97.07 #> 5 78-92 27 2.93 2.93 100.00 #> NA NA 0 0.00 NA NA #>
# different weight options frq(efc, c172code, weights = weights)
#> #> carer's level of education (c172code) <numeric> #> # total N=860 valid N=860 mean=1.98 sd=0.63 #> #> val label frq raw.prc valid.prc cum.prc #> 1 low level of education 176 20.47 20.47 20.47 #> 2 intermediate level of education 523 60.81 60.81 81.28 #> 3 high level of education 161 18.72 18.72 100.00 #> NA NA 0 0.00 NA NA #>
frq(efc, c172code, weights = "weights")
#> #> carer's level of education (c172code) <numeric> #> # total N=860 valid N=860 mean=1.98 sd=0.63 #> #> val label frq raw.prc valid.prc cum.prc #> 1 low level of education 176 20.47 20.47 20.47 #> 2 intermediate level of education 523 60.81 60.81 81.28 #> 3 high level of education 161 18.72 18.72 100.00 #> NA NA 0 0.00 NA NA #>
frq(efc, c172code, weights = efc$weights)
#> #> carer's level of education (c172code) <numeric> #> # total N=860 valid N=860 mean=1.98 sd=0.63 #> #> val label frq raw.prc valid.prc cum.prc #> 1 low level of education 176 20.47 20.47 20.47 #> 2 intermediate level of education 523 60.81 60.81 81.28 #> 3 high level of education 161 18.72 18.72 100.00 #> NA NA 0 0.00 NA NA #>
frq(efc$c172code, weights = efc$weights)
#> #> carer's level of education (xw) <numeric> #> # total N=860 valid N=860 mean=1.98 sd=0.63 #> #> val label frq raw.prc valid.prc cum.prc #> 1 low level of education 176 20.47 20.47 20.47 #> 2 intermediate level of education 523 60.81 60.81 81.28 #> 3 high level of education 161 18.72 18.72 100.00 #> NA NA 0 0.00 NA NA #>
# group string values dummy <- efc[1:50, 3, drop = FALSE] dummy$words <- sample( c("Hello", "Helo", "Hole", "Apple", "Ape", "New", "Old", "System", "Systemic"), size = nrow(dummy), replace = TRUE ) frq(dummy)
#> #> e16sex <numeric> #> # total N=50 valid N=50 mean=1.56 sd=0.50 #> #> val frq raw.prc valid.prc cum.prc #> 1 22 44 44 44 #> 2 28 56 56 100 #> <NA> 0 0 NA NA #> #> #> words <character> #> # total N=50 valid N=50 mean=4.70 sd=2.38 #> #> val frq raw.prc valid.prc cum.prc #> Ape 6 12 12 12 #> Hello 7 14 14 26 #> Helo 4 8 8 34 #> Hole 4 8 8 42 #> New 8 16 16 58 #> Old 9 18 18 76 #> System 3 6 6 82 #> Systemic 9 18 18 100 #> <NA> 0 0 NA NA #>
frq(dummy, grp.strings = 2)
#> #> e16sex <numeric> #> # total N=50 valid N=50 mean=1.56 sd=0.50 #> #> val frq raw.prc valid.prc cum.prc #> 1 22 44 44 44 #> 2 28 56 56 100 #> <NA> 0 0 NA NA #> #> #> words <character> #> # total N=50 valid N=50 mean=3.86 sd=1.73 #> #> val frq raw.prc valid.prc cum.prc #> Ape 6 12 12 12 #> Hello 7 14 14 26 #> Helo, Hole 8 16 16 42 #> New 8 16 16 58 #> Old 9 18 18 76 #> System, Systemic 12 24 24 100 #> <NA> 0 0 NA NA #>