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,
  min.frq = 0,
  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.

min.frq

Numeric, indicating the minimum frequency for which a value will be shown in the output (except for the missing values, prevailing show.na). Default value for min.frq is 0, so all value frequencies are shown. All values or categories that have less than min.frq occurences in the data will be summarized in a "n < 100" category.

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.

Details

The ...-argument not only accepts variable names or expressions from select_helpers. You can also use logical conditions, math operations, or combining variables to produce "crosstables". See 'Examples' for more details.

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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> ------------------------------------------------------------- #> 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(e42dep)
#> #> elder's dependency (e42dep) <numeric> #> # grouped by: male, low level of education #> # total N=80 valid N=80 mean=3.06 sd=0.92 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> ------------------------------------------------------------ #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> ------------------------------------------------------------ #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> ------------------------------------------------------------ #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> ------------------------------------------------------------ #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> ------------------------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> ------------------------------------------------------------ #> 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> #>
# show only categories with a minimal amount of frequencies frq(mtcars$gear)
#> #> x <numeric> #> # total N=32 valid N=32 mean=3.69 sd=0.74 #> #> Value | N | Raw % | Valid % | Cum. % #> ------------------------------------- #> 3 | 15 | 46.88 | 46.88 | 46.88 #> 4 | 12 | 37.50 | 37.50 | 84.38 #> 5 | 5 | 15.62 | 15.62 | 100.00 #> <NA> | 0 | 0.00 | <NA> | <NA> #>
frq(mtcars$gear, min.frq = 10)
#> #> x <numeric> #> # total N=32 valid N=32 mean=3.69 sd=0.74 #> #> Value | N | Raw % | Valid % | Cum. % #> -------------------------------------- #> 3 | 15 | 46.88 | 46.88 | 46.88 #> 4 | 12 | 37.50 | 37.50 | 84.38 #> n < 10 | 5 | 15.62 | 15.62 | 100.00 #> <NA> | 0 | 0.00 | <NA> | <NA> #>
frq(mtcars$gear, min.frq = 15)
#> #> x <numeric> #> # total N=32 valid N=32 mean=3.69 sd=0.74 #> #> Value | N | Raw % | Valid % | Cum. % #> -------------------------------------- #> 3 | 15 | 46.88 | 46.88 | 46.88 #> n < 15 | 17 | 53.12 | 53.12 | 100.00 #> <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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> -------------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> -------------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> -------------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> -------------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> -------------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> -------------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> -------------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> -------------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> -------------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> ----------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> ------------------------------------------------------------------------ #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> ---------------------------------------------- #> 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 #> #> Value | N | Raw % | Valid % | Cum. % #> ------------------------------------------ #> 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> #>
# 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 #> #> Value | N | Raw % | Valid % | Cum. % #> ------------------------------------- #> 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 #> #> Value | N | Raw % | Valid % | Cum. % #> -------------------------------------- #> 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 #> #> Value | N | Raw % | Valid % | Cum. % #> ------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> ---------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> ------------------------------------------------------------------------ #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> ------------------------------------------------------------------------ #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> ------------------------------------------------------------------------ #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> ------------------------------------------------------------------------ #> 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 #> #> Value | N | Raw % | Valid % | Cum. % #> ------------------------------------- #> 1 | 22 | 44.00 | 44.00 | 44 #> 2 | 28 | 56.00 | 56.00 | 100 #> <NA> | 0 | 0.00 | <NA> | <NA> #> #> #> words <character> #> # total N=50 valid N=50 mean=4.70 sd=2.38 #> #> Value | N | Raw % | Valid % | Cum. % #> --------------------------------------- #> Ape | 6 | 12.00 | 12.00 | 12.00 #> Hello | 7 | 14.00 | 14.00 | 26.00 #> Helo | 4 | 8.00 | 8.00 | 34.00 #> Hole | 4 | 8.00 | 8.00 | 42.00 #> New | 8 | 16.00 | 16.00 | 58.00 #> Old | 9 | 18.00 | 18.00 | 76.00 #> System | 3 | 6.00 | 6.00 | 82.00 #> Systemic | 9 | 18.00 | 18.00 | 100.00 #> <NA> | 0 | 0.00 | <NA> | <NA> #>
frq(dummy, grp.strings = 2)
#> #> e16sex <numeric> #> # total N=50 valid N=50 mean=1.56 sd=0.50 #> #> Value | N | Raw % | Valid % | Cum. % #> ------------------------------------- #> 1 | 22 | 44.00 | 44.00 | 44 #> 2 | 28 | 56.00 | 56.00 | 100 #> <NA> | 0 | 0.00 | <NA> | <NA> #> #> #> words <character> #> # total N=50 valid N=50 mean=3.86 sd=1.73 #> #> Value | N | Raw % | Valid % | Cum. % #> ------------------------------------------------ #> Ape | 6 | 12.00 | 12.00 | 12.00 #> Hello | 7 | 14.00 | 14.00 | 26.00 #> Helo, Hole | 8 | 16.00 | 16.00 | 42.00 #> New | 8 | 16.00 | 16.00 | 58.00 #> Old | 9 | 18.00 | 18.00 | 76.00 #> System, Systemic | 12 | 24.00 | 24.00 | 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 #> #> Value | N | Raw % | Valid % | Cum. % #> ------------------------------------- #> 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 #> #> Value | N | Raw % | Valid % | Cum. % #> -------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> -------------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> -------------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> -------------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> -------------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> -------------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> -------------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> -------------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> -------------------------------------------------- #> 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 #> #> Value | Label | N | Raw % | Valid % | Cum. % #> -------------------------------------------------- #> 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 #> #> Value | N | Raw % | Valid % | Cum. % #> ------------------------------------- #> 1.00 | 1 | 0.67 | 0.67 | 0.67 #> 1.10 | 1 | 0.67 | 0.67 | 1.33 #> 1.20 | 2 | 1.33 | 1.33 | 2.67 #> 1.30 | 7 | 4.67 | 4.67 | 7.33 #> 1.40 | 13 | 8.67 | 8.67 | 16.00 #> 1.50 | 13 | 8.67 | 8.67 | 24.67 #> 1.60 | 7 | 4.67 | 4.67 | 29.33 #> 1.70 | 4 | 2.67 | 2.67 | 32.00 #> 1.90 | 2 | 1.33 | 1.33 | 33.33 #> 3.00 | 1 | 0.67 | 0.67 | 34.00 #> 3.30 | 2 | 1.33 | 1.33 | 35.33 #> 3.50 | 2 | 1.33 | 1.33 | 36.67 #> 3.60 | 1 | 0.67 | 0.67 | 37.33 #> 3.70 | 1 | 0.67 | 0.67 | 38.00 #> 3.80 | 1 | 0.67 | 0.67 | 38.67 #> 3.90 | 3 | 2.00 | 2.00 | 40.67 #> 4.00 | 5 | 3.33 | 3.33 | 44.00 #> 4.10 | 3 | 2.00 | 2.00 | 46.00 #> 4.20 | 4 | 2.67 | 2.67 | 48.67 #> 4.30 | 2 | 1.33 | 1.33 | 50.00 #> 4.40 | 4 | 2.67 | 2.67 | 52.67 #> 4.50 | 8 | 5.33 | 5.33 | 58.00 #> 4.60 | 3 | 2.00 | 2.00 | 60.00 #> 4.70 | 5 | 3.33 | 3.33 | 63.33 #> 4.80 | 4 | 2.67 | 2.67 | 66.00 #> 4.90 | 5 | 3.33 | 3.33 | 69.33 #> 5.00 | 4 | 2.67 | 2.67 | 72.00 #> 5.10 | 8 | 5.33 | 5.33 | 77.33 #> 5.20 | 2 | 1.33 | 1.33 | 78.67 #> 5.30 | 2 | 1.33 | 1.33 | 80.00 #> 5.40 | 2 | 1.33 | 1.33 | 81.33 #> 5.50 | 3 | 2.00 | 2.00 | 83.33 #> 5.60 | 6 | 4.00 | 4.00 | 87.33 #> 5.70 | 3 | 2.00 | 2.00 | 89.33 #> 5.80 | 3 | 2.00 | 2.00 | 91.33 #> 5.90 | 2 | 1.33 | 1.33 | 92.67 #> 6.00 | 2 | 1.33 | 1.33 | 94.00 #> 6.10 | 3 | 2.00 | 2.00 | 96.00 #> 6.30 | 1 | 0.67 | 0.67 | 96.67 #> 6.40 | 1 | 0.67 | 0.67 | 97.33 #> 6.60 | 1 | 0.67 | 0.67 | 98.00 #> 6.70 | 2 | 1.33 | 1.33 | 99.33 #> 6.90 | 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 #> #> Value | N | Raw % | Valid % | Cum. % #> ------------------------------------- #> 0.10 | 5 | 3.33 | 3.33 | 3.33 #> 0.20 | 29 | 19.33 | 19.33 | 22.67 #> 0.30 | 7 | 4.67 | 4.67 | 27.33 #> 0.40 | 7 | 4.67 | 4.67 | 32.00 #> 0.50 | 1 | 0.67 | 0.67 | 32.67 #> 0.60 | 1 | 0.67 | 0.67 | 33.33 #> 1.00 | 7 | 4.67 | 4.67 | 38.00 #> 1.10 | 3 | 2.00 | 2.00 | 40.00 #> 1.20 | 5 | 3.33 | 3.33 | 43.33 #> 1.30 | 13 | 8.67 | 8.67 | 52.00 #> 1.40 | 8 | 5.33 | 5.33 | 57.33 #> 1.50 | 12 | 8.00 | 8.00 | 65.33 #> 1.60 | 4 | 2.67 | 2.67 | 68.00 #> 1.70 | 2 | 1.33 | 1.33 | 69.33 #> 1.80 | 12 | 8.00 | 8.00 | 77.33 #> 1.90 | 5 | 3.33 | 3.33 | 80.67 #> 2.00 | 6 | 4.00 | 4.00 | 84.67 #> 2.10 | 6 | 4.00 | 4.00 | 88.67 #> 2.20 | 3 | 2.00 | 2.00 | 90.67 #> 2.30 | 8 | 5.33 | 5.33 | 96.00 #> 2.40 | 3 | 2.00 | 2.00 | 98.00 #> 2.50 | 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 #> #> Value | N | Raw % | Valid % | Cum. % #> -------------------------------------- #> FALSE | 32 | 21.33 | 21.33 | 21.33 #> TRUE | 118 | 78.67 | 78.67 | 100.00 #> <NA> | 0 | 0.00 | <NA> | <NA> #>
# computation of variables "on the fly" frq(mtcars, (gear + carb) / cyl)
#> #> (gear + carb)/cyl <numeric> #> # total N=32 valid N=32 mean=1.12 sd=0.38 #> #> Value | N | Raw % | Valid % | Cum. % #> ------------------------------------ #> 0.62 | 4 | 12.50 | 12.50 | 12.50 #> 0.67 | 2 | 6.25 | 6.25 | 18.75 #> 0.75 | 3 | 9.38 | 9.38 | 28.12 #> 0.88 | 5 | 15.62 | 15.62 | 43.75 #> 1.00 | 1 | 3.12 | 3.12 | 46.88 #> 1.12 | 1 | 3.12 | 3.12 | 50.00 #> 1.25 | 4 | 12.50 | 12.50 | 62.50 #> 1.33 | 4 | 12.50 | 12.50 | 75.00 #> 1.50 | 4 | 12.50 | 12.50 | 87.50 #> 1.62 | 1 | 3.12 | 3.12 | 90.62 #> 1.75 | 2 | 6.25 | 6.25 | 96.88 #> 1.83 | 1 | 3.12 | 3.12 | 100.00 #> <NA> | 0 | 0.00 | <NA> | <NA> #>
# crosstables set.seed(123) d <- data.frame( var_x = sample(letters[1:3], size = 30, replace = TRUE), var_y = sample(1:2, size = 30, replace = TRUE), var_z = sample(LETTERS[8:10], size = 30, replace = TRUE) ) table(d$var_x, d$var_z)
#> #> H I J #> a 1 5 2 #> b 3 4 4 #> c 6 2 3
frq(d, paste0(var_x, var_z))
#> #> paste0(var_x, var_z) <character> #> # total N=30 valid N=30 mean=5.27 sd=2.38 #> #> Value | N | Raw % | Valid % | Cum. % #> ------------------------------------ #> aH | 1 | 3.33 | 3.33 | 3.33 #> aI | 5 | 16.67 | 16.67 | 20.00 #> aJ | 2 | 6.67 | 6.67 | 26.67 #> bH | 3 | 10.00 | 10.00 | 36.67 #> bI | 4 | 13.33 | 13.33 | 50.00 #> bJ | 4 | 13.33 | 13.33 | 63.33 #> cH | 6 | 20.00 | 20.00 | 83.33 #> cI | 2 | 6.67 | 6.67 | 90.00 #> cJ | 3 | 10.00 | 10.00 | 100.00 #> <NA> | 0 | 0.00 | <NA> | <NA> #>
frq(d, paste0(var_x, var_y, var_z))
#> #> paste0(var_x, var_y, var_z) <character> #> # total N=30 valid N=30 mean=6.97 sd=3.69 #> #> Value | N | Raw % | Valid % | Cum. % #> ------------------------------------ #> a1H | 1 | 3.33 | 3.33 | 3.33 #> a1J | 2 | 6.67 | 6.67 | 10.00 #> a2I | 5 | 16.67 | 16.67 | 26.67 #> b1H | 2 | 6.67 | 6.67 | 33.33 #> b1I | 3 | 10.00 | 10.00 | 43.33 #> b1J | 2 | 6.67 | 6.67 | 50.00 #> b2H | 1 | 3.33 | 3.33 | 53.33 #> b2I | 1 | 3.33 | 3.33 | 56.67 #> b2J | 2 | 6.67 | 6.67 | 63.33 #> c1H | 5 | 16.67 | 16.67 | 80.00 #> c1I | 2 | 6.67 | 6.67 | 86.67 #> c1J | 3 | 10.00 | 10.00 | 96.67 #> c2H | 1 | 3.33 | 3.33 | 100.00 #> <NA> | 0 | 0.00 | <NA> | <NA> #>