freq.table: Frequency Table

Description Usage Arguments Details Value Examples

View source: R/freq.table.R

Description

The function freq.table computes a frequency table with absolute and relative frequencies (for non-ordered variables); and with those as well as their cumulative counterparts (for ordered variables).

Usage

1
freq.table(x, cont, ord = NULL)

Arguments

x

a vector containing the sample provided to compute the frequency table

cont

logical; if TRUE, the sample comes from a continuous variable; if FALSE the sample is treated as coming from a discrete or categorical variable.

ord

if needed, character vector containing the ordered categories' names of the ordinal variable.

Details

The procedure used to define the intervals for the frequency table in the continuous case is the same as used for the histogram (see ?Histogram).

Value

A list containing the following components:

ni

a numeric vector containing the absolute frequencies.

fi

a numeric vector containing the relative frequencies.

Ni

a numeric vector containing the absolute cumulative frequencies.

Fi

a numeric vector containing the relative cumulative frequencies.

di

if cont=TRUE, a vector containing the frequency density.

tab

the frequency table.

The values of the cumulative frequencies (Ni and Fi) are only computed and provided when the variable of interest is ordered. If the user does not save those values, the function provides the list on the console.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#Nominal variable
x=sample(c("yellow","red","blue","green"),size=20,replace=TRUE)
freq.table(x,cont=FALSE)

#Ordinal variable
x=sample(c("high","small","medium"),size=20,replace=TRUE)
freq.table(x,cont=FALSE,ord=c("small","medium","high"))

#Discrete variable
x=sample(1:5,size=20,replace=TRUE)
freq.table(x,cont=FALSE)

#Continuous variable
x=rnorm(20)
freq.table(x,cont=TRUE)

LearningStats documentation built on April 21, 2021, 9:06 a.m.