Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

fdt

Frequency distribution table for numerical data


Description

A S3 set of methods to easily perform frequency distribution table (fdt) from vector, data.frame and matrix objects.

Usage

## S3 generic
fdt(x, ...)

## S3 methods
## Default S3 method:
fdt(x,
    k,
    start,
    end,
    h,
    breaks=c('Sturges', 'Scott', 'FD'),
    right=FALSE, ...)

## S3 method for class 'data.frame'
fdt(x,
    k,
    by,
    breaks=c('Sturges', 'Scott', 'FD'),
    right=FALSE, ...)

## S3 method for class 'matrix'
fdt(x,
    k,
    breaks=c('Sturges', 'Scott', 'FD'),
    right=FALSE, ...)

Arguments

x

A vector, data.frame or matrix object. If x is data.frame or matrix it must contain at least one numeric column.

k

Number of class intervals.

start

Left endpoint of the first class interval.

end

Right endpoint of the last class interval.

h

Class interval width.

by

Categorical variable used for grouping each numeric variable, useful only on data.frame.

breaks

Method used to determine the number of interval classes, c(“Sturges”, “Scott”, “FD”).

right

Right endpoints open (default = FALSE).

...

Potencial further arguments (required by generic).

Details

The simplest way to run fdt is done by supplying only the x object, for example: nm <- fdt(x). In this case all necessary default values (breaks and right) (“Sturges” and FALSE respectively) will be used.

It can be provided also:

  • x and k (number of class intervals);

  • x, start (left endpoint of the first class interval) and end (right endpoint of the last class interval); or

  • x, start, end and h (class interval width).

These options make the fdt very easy and flexible.

The fdt object stores information to be used by methods summary, print, plot, mean, median and mfv. The result of plot is a histogram. The methods summary, print and plot provide a reasonable set of parameters to format and plot the fdt object in a pretty (and publishable) way.

Value

For fdt the method fdt.default returns a list of class fdt.default with the slots:

table

A data.frame storing the fdt;

breaks

A vector of length 4 storing start, end, h and right of the fdt generated by this method;

data

A vector of the data x provided.

The methods fdt.data.frame and fdt.matrix return a list of class fdt.multiple. This list has one slot for each numeric (fdt) variable of the x provided. Each slot, corresponding to each numeric variable, stores the same slots of the fdt.default described above.

Author(s)

José Cláudio Faria
Enio G. Jelihovschi
Ivan B. Allaman

See Also

hist provided by graphics and table, cut both provided by base.

Examples

library(fdth)

##========
## Vector
##========
x <- rnorm(n=1e3,
           mean=5,
           sd=1)

# x
(fdt <- fdt(x))

# x, alternative breaks
(fdt <- fdt(x,
            breaks='Scott'))

# x, k
(fdt <- fdt(x,
            k=10))

# x, star, end
range(x)

(fdt <- fdt(x,
            start=floor(min(x)),
            end=floor(max(x) + 1)))

# x, start, end, h
(fdt <- fdt(x,
            start=floor(min(x)),
            end=floor(max(x) + 1),
            h=1))

# Effect of right
x <- rep(1:3, 3); sort(x)

(fdt <- fdt(x,
            start=1,
            end=4,
            h=1))

(fdt <- fdt(x,
            start=0,
            end=3,
            h=1,
            right=TRUE))

##================================================
## Data.frame: multivariated with two categorical
##================================================
mdf <- data.frame(c1=sample(LETTERS[1:3], 1e2, TRUE),
                  c2=as.factor(sample(1:10, 1e2, TRUE)),
                  n1=c(NA, NA, rnorm(96, 10, 1), NA, NA),
                  n2=rnorm(100, 60, 4),
                  n3=rnorm(100, 50, 4),
                  stringsAsFactors=TRUE)

head(mdf)

(fdt <- fdt(mdf))

# By factor!
(fdt <- fdt(mdf,
            k=5,
            by='c1'))

# choose FD criteria               
(fdt <- fdt(mdf,
            breaks='FD',
            by='c1'))

(fdt <- fdt(mdf,
            k=5,
            by='c2'))

(fdt <- fdt(iris,
            k=10))

(fdt <- fdt(iris,
            k=5,
            by='Species'))

#=========================
# Matrices: multivariated
#=========================
(fdt <-fdt(state.x77))

fdth

Frequency Distribution Tables, Histograms and Polygons

v1.2-5
GPL (>= 2)
Authors
Jos<e9> Cl<e1>udio Faria, Enio G. Jelihovschi and Ivan B. Allaman
Initial release
2020-04-17

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.