| print.fdt | R Documentation |
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.
## 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, ...)
x |
a ‘fdt’ object. |
columns |
a |
round |
rounds ‘fdt’ columns to the specified number of decimal places (default 2). |
format.classes |
logical, if |
pattern |
same as |
row.names |
logical (or character vector), indicating whether (or what)
row names should be printed. The default is |
right |
logical, indicating whether or not strings should be right-aligned. The default is right-alignment. |
... |
potential further arguments (required by generic). |
For print.fdt, it is possible to select which 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 which columns of the table
(a data.frame) will be shown. The columns are:
‘Class limits’
‘f’ - absolute frequency
‘rf’ - relative frequency
‘rf(%)’ - relative frequency, %
‘cf’ - cumulative frequency
‘cf(%)’ - cumulative frequency, %
The available parameters offer an easy and powerful way to format the ‘fdt’ for publications and other purposes.
A single data.frame for fdt.default and fdt_cat.default, or multiple
data.frames for fdt.multiple and fdt_cat.multiple.
Faria, J. C.
Allaman, I. B
Jelihovschi, E. G.
library (fdth)
#=====================
# Vectors: univariate
#=====================
set.seed(1)
x <- rnorm(n = 1e3,
mean = 5,
sd = 1)
ft <- fdt(x)
str(ft)
ft
print(ft) # same result
print(ft,
format = TRUE) # It may not be what you want for publication!
print(ft,
format = TRUE,
pattern = '%.2f') # Better, but can it be improved?
print(ft,
col = c(1:2, 4, 6),
format = TRUE,
pattern = '%.2f') # Yes, it can!
range(x) # To inspect the range of x
print(fdt(x,
start = 1,
end = 9,
h = 1),
col = c(1:2, 4, 6),
format = TRUE,
pattern = '%d') # Is it nice now?
ft[['table']] # Stores the frequency distribution table (fdt)
ft[['breaks']] # Stores the breaks of fdt
ft[['breaks']]['start'] # Stores the left value of the first class
ft[['breaks']]['end'] # Stores the right value of the last class
ft[['breaks']]['h'] # Stores the class interval
as.logical(ft[['breaks']]['right']) # Stores the right option
#======================================================
# Data.frames: multivariate with categorical variables
#======================================================
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)
(ft <- fdt_cat(mdf))
print(ft)
(ft <- fdt(mdf,
na.rm = TRUE))
print(ft)
str(ft)
print(ft, # the s
format = TRUE)
print(ft,
format = TRUE,
pattern = '%05.2f') # regular expression
print(ft,
col = c(1:2, 4, 6),
format = TRUE,
pattern = '%05.2f')
print(ft,
col = c(1:2, 4, 6))
print(ft,
col = c(1:2, 4, 6),
format = TRUE,
pattern = '%05.2f')
levels(mdf$X1)
print(fdt(mdf,
k = 5,
by = 'X1',
na.rm = TRUE))
levels(mdf$X2)
print(fdt(mdf,
breaks = 'FD',
by = 'X2',
na.rm = TRUE),
round = 3)
print(fdt(mdf,
k = 5,
by = 'X2',
na.rm = TRUE),
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: multivariate
#========================
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')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.