DescTools (version 0.99.14)

Desc.factor: Describe a Factor, an Ordered Factor Or a Character Vector

Description

This function produces a rich description of a factor, containing length, number of NAs, number of levels and detailed frequencies of all levels. The order of the frequency table can be chosen between descending/ascending frequency, labels or levels. For ordered factors the order default is "level". Character vectors are treated as unordered factors.

Usage

## S3 method for class 'factor':
Desc(x, main = NULL, ord = c("desc", "asc", "name", "level"),
     maxrows = 12, digits = NULL, plotit = getOption("plotit", FALSE), ...)

## S3 method for class 'ordered':
Desc(x, main = NULL, ...)

## S3 method for class 'character':
Desc(x, main = NULL, ...)

Arguments

x
a single factor, an ordered factor or a character vector to be described.
main
the caption of the output. If this is set to NULL (which is the default) the name of the factor and its class will be printed. Use NA if no caption should be printed at all.
ord
the order for the frequency table. Factors (and character vectors) are by default orderd by their descending frequencies, ordered factors by their natural order. If a character e.g. should be ordered alphabetical, set ord to name.
maxrows
numeric value. Defines the maximum number of rows to be reported. For factors with lots of levels it is often not interesting to see all the levels. Default is hence set to 12 most frequent ones (resp. the first ones if ord is set to
digits
integer. With how many digits shoud the relative frequencies be formatted? Default is 1.
plotit
boolean. Should a plot be created? Default is FALSE. The factor is plotted with PlotDesc.factor.
...
further argument to be passed to methods. For ordered factors and character vectors they are passed to Desc.factor.

Value

  • A list containing the following components:
  • lengththe length of the vector
  • nthe valid entries (NAs are excluded)
  • NAsnumber of NAs
  • levelsnumber of levels
  • uniquenumber of unique values. Note that need not be the same, as there might be empty levels. Of course unique values can never be less than the number of levels.
  • dupesboolean saying whether there are any duplicates in the vector.
  • frqa data.frame of absolute and relative frequencies given by Freq

Details

Desc.char converts x to a factor an processes x as factor. Desc.ordered does nothing more than changing the standard order for the frequencies to it's intrinsic order, which means order "level" instead of "desc" in the factor case.

See Also

Desc, PlotDesc

Examples

Run this code
# unordered factor
Desc(d.diamonds$colour)

# ordered factor
Desc(d.diamonds$clarity)

# just the 5 first groups of the factor
Desc(d.diamonds$colour, maxrows = 5)

# just as many rows, as the most frequent 80% of the factor levels use
Desc(d.diamonds$colour, maxrows = 0.8)

Run the code above in your browser using DataLab