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

print

Print methods for fdt objects


Description

S3 methods to return a data.frame (the frequency distribution table - fdt) for fdt.default and fdt.multiple objects; data.frame (the frequency distribution table - fdt_cat) for fdt_cat.default and fdt_cat.multiple objects.

Usage

## S3 methods
## S3 method for class 'fdt.default'
print(x,
      columns=1:6,
      round=2,
      format.classes=FALSE,
      pattern='%09.3e',
      row.names=FALSE,
      right=TRUE, ...)

## S3 method for class 'fdt.multiple'
print(x,
      columns=1:6,
      round=2,
      format.classes=FALSE,
      pattern='%09.3e',
      row.names=FALSE,
      right=TRUE, ...)

## S3 method for class 'fdt_cat.default'
print(x,
      columns=1:6,
      round=2,
      row.names=FALSE,
      right=TRUE, ...)

## S3 method for class 'fdt_cat.multiple'
print(x,
      columns=1:6,
      round=2,
      row.names=FALSE,
      right=TRUE, ...)

Arguments

x

A fdt object.

columns

A vector of integers to select columns of the data.frame table.

round

Rounds fdt columns to the specified number of decimal places (default 2).

format.classes

Logical, if TRUE the first column of the data.frame table will be formated using regular expression. The default is “%09.3e”.

pattern

Same as fmt in sprintf.

row.names

Logical (or character vector), indicating whether (or what) row names should be printed. The default is FALSE.

right

Logical, indicating whether or not strings should be right-aligned. The default is right-alignment.

...

Potential further arguments (require by generic).

Details

For print.fdt, it is possible to select what columns of the table (a data.frame) will be shown, as well as the pattern of the first column, for print.fdt_cat it is only possible to select what columns of the table (a data.frame) will be shown. The columns are:

  1. Class limits

  2. f - Absolute frequency

  3. rf - Relative frequency

  4. rf(%) - Relative frequency, %

  5. cf - Cumulative frequency

  6. cf(%) - Cumulative frequency, %

The available parameters offer an easy and powerful way to format the fdt for publications and other purposes.

Value

A single data.frame for fdt.default and fdt.default or multiple data.frames for fdt.multiple and fdt_cat.multiple.

Author(s)

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

Examples

library (fdth)

#======================
# Vectors: univariated
#======================
set.seed(1)

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

d <- fdt(x)

str(d)

d

print(d) # the same

print(d,
      format=TRUE)      # It can not be what you want to publications!

print(d,
      format=TRUE,
      pattern='%.2f')   # Huumm ..., good, but ... Can it be better?

print(d,
      col=c(1:2, 4, 6),
      format=TRUE, 
      pattern='%.2f')   # Yes, it can!

range(x)                # To know x

print(fdt(x,
          start=1,
          end=9,
          h=1),
      col=c(1:2, 4, 6),
      format=TRUE,
      pattern='%d')     # Is it nice now?

d[['table']]                        # Stores the feq. dist. table (fdt)
d[['breaks']]                       # Stores the breaks of fdt
d[['breaks']]['start']              # Stores the left value of the first class
d[['breaks']]['end']                # Stores the right value of the last class
d[['breaks']]['h']                  # Stores the class interval
as.logical(d[['breaks']]['right'])  # Stores the right option

#=============================================
# Data.frames: multivariated with categorical
#=============================================
mdf <- data.frame(X1=rep(LETTERS[1:4], 25),
                  X2=as.factor(rep(1:10, 10)),
                  Y1=c(NA, NA, rnorm(96, 10, 1), NA, NA),
                  Y2=rnorm(100, 60, 4),
                  Y3=rnorm(100, 50, 4),
                  Y4=rnorm(100, 40, 4),
                  stringsAsFactors=TRUE)
                  
(d <- fdt_cat(mdf))
                  
print(d)                  

(d <- fdt(mdf))

print(d)

str(d)

print(d, # the s
      format=TRUE)

print(d,
      format=TRUE,
      pattern='%05.2f')  # regular expression

print(d,
      col=c(1:2, 4, 6), 
      format=TRUE, 
      pattern='%05.2f')

print(d,
      col=c(1:2, 4, 6))

print(d,
      col=c(1:2, 4, 6),
      format=TRUE,
      pattern='%05.2f')

levels(mdf$X1)

print(fdt(mdf,
          k=5,
          by='X1'))

levels(mdf$X2)

print(fdt(mdf,
          breaks='FD',
          by='X2'),
      round=3)

print(fdt(mdf,
          k=5,
          by='X2'),
      format=TRUE,
      round=3)

print(fdt(iris,
          k=5),
      format=TRUE,
      patter='%04.2f')

levels(iris$Species)

print(fdt(iris,
          k=5,
          by='Species'),
      format=TRUE, 
      patter='%04.2f')

#=========================
# Matrices: multivariated
#=========================
print(fdt(state.x77), 
      col=c(1:2, 4, 6),
      format=TRUE)

print(fdt(volcano,
          right=TRUE),
      col=c(1:2, 4, 6),
      round=3,
      format=TRUE,
      pattern='%05.1f')

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.