make.fdt: Frequency distribution table for continuous and categorical...

View source: R/make.fdt.R

make.fdtR Documentation

Frequency distribution table for continuous and categorical variables

Description

Creates a complete fdt from a minimal set of information.
Useful to reproduce a previous fdt when the original data vector is not known.

Usage

make.fdt(f,
         start,
         end,
         right=FALSE)

make.fdt_cat(f,
             categories=NULL,
             sort=TRUE,
             decreasing=TRUE)

Arguments

f

a numeric vector object of frequencies.

start

the left value of the interval of the first class.

end

the last value of the interval of the last class.

right

intervals open on the right (default = FALSE).

categories

the levels of the categorical variable.

sort

the levels of the categorical variable will be ordered by frequency. The default is TRUE.

decreasing

if sort argument is TRUE, the order will be decreasing by default.

Details

Given the starting and ending values of the continuous-variable table or the levels of the categorical variable plus the number of intervals and the absolute frequency values the functions make.fdt and make.fdt_cat reconstruct complete fdt or fdt_cat tables.

Value

The function make.fdt returns a list 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.

The function make.fdt_cat returns a list with the slots:

Category

the levels of the categorical variable.

f

absolute frequency, numeric

rf

relative frequency, numeric

rf(%)

relative frequency in percentages, numeric

cf

cumulative frequency; numeric

cf(%)

cumulative frequency in percentages, numeric

Author(s)

Faria, J. C.
Allaman, I. B
Jelihovschi, E. G.

See Also

table and cut provided by base package.

Examples

library(fdth)

# Numeric
# Making one reference fdt
set.seed(33)
x <- rnorm(1e3, 
           20, 
           2)

(ft.r <- fdt(x))

# Making a brand new
(ft.n  <- make.fdt(f=ft.r$table$f,
                   start=13.711,
                   end=27.229))   # Good, but can it be improved?

summary(ft.n,
        format=TRUE,
        pattern='%.3f')           # Is it nice now?


# Categorical
x <- sample(letters[1:5], 
            1e3, 
            rep=TRUE)

# Making one reference fdt
(ft.r <- fdt_cat(x))

# Making a brand new
(ft.n <- make.fdt_cat(f=ft.r$f,
                      categ=ft.r$Category))

fdth documentation built on May 12, 2026, 1:08 a.m.