View source: R/UBStats_Main_Visible_ALL_202406.R
distr.table.x | R Documentation |
distr.table.x()
computes the frequency table of a vector or a factor.
distr.table.x(
x,
freq = c("counts", "proportions"),
total = TRUE,
breaks,
adj.breaks = TRUE,
interval = FALSE,
f.digits = 2,
p.digits = 0,
d.digits = 5,
force.digits = FALSE,
use.scientific = FALSE,
data,
...
)
x |
An unquoted string identifying the variable whose
distribution has to be analysed. |
freq |
A character vector specifying the set of frequencies to be
displayed (more options are allowed). Allowed options (possibly abbreviated)
are |
total |
Logical value indicating whether the sum of the requested
frequencies should be added to the table; default to |
breaks |
Allows to classify a numerical variable |
adj.breaks |
Logical value indicating whether the endpoints of
intervals of a numerical variable |
interval |
Logical value indicating whether |
f.digits , p.digits , d.digits |
Integer values specifying the number of
decimals used to round respectively proportions (default: |
force.digits |
Logical value indicating whether frequencies and
densities should be forcedly rounded to the number of decimals specified in
|
use.scientific |
Logical value indicating whether numbers
in tables (typically densities) should be displayed using
scientific notation ( |
data |
An optional data frame containing |
... |
Additional arguments to be passed to low level functions. |
A table (converted to dataframe) listing the values taken by the variable, arranged in standard order (logical, alphabetical or numerical order for vectors, order of levels for factors, ordered intervals for classified variables or for variables measured in classes), and the requested set of frequencies.
Raffaella Piccarreta raffaella.piccarreta@unibocconi.it
distr.plot.x()
for plotting a univariate
distribution.
distr.table.xy()
for tabulating a bivariate
distribution.
distr.plot.xy()
for plotting a bivariate
distribution.
data(MktDATA, package = "UBStats")
# Character vectors, factors, and discrete numeric vectors
distr.table.x(Education, data = MktDATA)
distr.table.x(Children, freq = c("count","prop","cum"),
data = MktDATA)
# Numerical variable classified into intervals
# - Classes of equal width
distr.table.x(AOV, breaks = 6, freq = c("Count","Prop","Perc","Cum"),
p.digits = 2, data = MktDATA)
# - Classes with specified endpoints
distr.table.x(AOV, breaks = c(0,20,30,50,100,180),
freq = c("Count","Perc","Cum","Densities"),
p.digits = 2, data = MktDATA)
# Numerical variable measured in classes
# - Variable measured in classes
distr.table.x(Income, freq = c("count","prop","cum","dens"),
interval = TRUE, data = MktDATA)
# - An example of non-consistent intervals.
# Densities are not calculated
x.inconsistent <- c(rep("0;10",30),rep("10;20",25),rep("25;8",25),
rep("15;31",15),rep("20;45",16),rep("30;40",18))
distr.table.x(x.inconsistent, freq = c("count","prop","cum","dens"),
interval = TRUE)
# Arguments adj.breaks, use.scientific, and force.digits
# A variable with a very wide range (very small densities)
LargeX <- MktDATA$AOV*5000000
# - Default: manages possible excess of rounding
distr.table.x(LargeX, breaks = 5,
freq = c("count","percent","densities"))
# - Forcing digits to the default values
distr.table.x(LargeX, breaks = 5,
freq=c("count","percent","dens"),
force.digits = TRUE)
# - Scientific notation for frequencies/densities
distr.table.x(LargeX, breaks = 5,
freq = c("count","percent","dens"),
use.scientific = TRUE)
# - Scientific notation both for intervals’ endpoints
# and for frequencies/densities
distr.table.x(LargeX, breaks = 5, adj.breaks = FALSE,
freq = c("count","percent","dens"),
use.scientific = TRUE)
# Output a dataframe with the table
table.AOV<-distr.table.x(AOV, breaks = c(0,20,30,50,100,180),
freq = c("Count","Perc","Cum","Dens"),
data = MktDATA)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.