freq_table: Frequency table

Description Usage Arguments Value Author(s) Examples

View source: R/freq_table.R

Description

Compute the frequency table of a categorical or a numerical series.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
freq_table(
  data,
  x,
  f = "n",
  vals = NULL,
  weights = NULL,
  total = FALSE,
  max = NULL,
  breaks = NULL,
  right = NULL,
  xfirst = NULL,
  xlast = NULL,
  wlast = NULL,
  freq = NULL,
  mass = NULL,
  center = NULL
)

Arguments

data

a tibble,

x

a categorical or numerical series,

f

a string containing n for counts, f for relative frequencies, p for percentages and m for mass frequencies. Cumulative series are obtained using the same letters in upper caps,

vals

a character containing letters indicating the values of the variable that should be returned; x for the center of the class, l and u for the lower and upper limit of the class, a for the range,

weights

a series that contain the weights that enable the sample to mimic the population,

total

a logical indicating whether the total should be returned,

max

if the series is a discrete numerical value, this argument indicates that all the values greater than max should be merged in the same modality,

breaks

a numerical vector of class limits,

right

a logical indicating whether classes should be closed (right = TRUE) or open (right = FALSE) on the right,

xfirst, xlast, wlast

see as_numeric(),

freq

a series that contains the frequencies (only relevant if data is already a frequency table),

mass

a series that contains the masses of the variable (only relevant if data is already a frequency table),

center

a series that contains the center of the class of the variable (only relevant if data is already a frequency table).

Value

a tibble containing the specified values of vals and f.

Author(s)

Yves Croissant

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# in table padova, price is a numeric variable, a vector of breaks should be provided
library("dplyr")
padova %>% freq_table(price,
                      breaks = c(50, 100, 150, 200, 250, 300, 350, 400),
                      right = TRUE)
# return relative frequencies and densities, and the center value
# of the series and the width of the bin
padova %>% freq_table(price,
                      breaks = c(50, 100, 150, 200, 250, 300, 350, 400),
                      right = TRUE, f = "fd", vals = "xa")
# in table wages, wage is a factor that represents the classes
wages %>% freq_table(wage, "d")
# a breaks argument is provided to reduce the number of classes
wages %>% freq_table(wage, breaks = c(10, 20, 30, 40, 50))
# a total argument add a total to the frequency table
wages %>% freq_table(wage, breaks = c(10, 20, 30, 40, 50), total = TRUE)
# ├Čncome is already a frequency table, the freq argument
# is mandatory
income %>% freq_table(inc_class, freq = number)
# the mass argument can be indicated if on column contains the
# mass of the series in each bin. In this case, the center of the
# class are exactly the mean of the series in each bin
income %>% freq_table(inc_class, freq = number, mass = tot_inc)
# rgp contains a children series which indicates the number of
# children of the households
rgp %>% freq_table(children)
# a max argument can be indicated to merge the unusual high
# values of number of childre
rgp %>% freq_table(children, max = 4)
# employment is a non random survey, there is a weights series
# that can be used to compute the frequency table according to the
# sum of weights and not to counts
employment %>% freq_table(education)
employment %>% freq_table(education, weights = weights)

descstat documentation built on Feb. 17, 2021, 5:07 p.m.