frequencyTable: Number of value occurrences in columns

View source: R/dataFrame.R

frequencyTableR Documentation

Number of value occurrences in columns

Description

Counts the number of occurrences of the different values in each column of a data frame

Usage

frequencyTable(
  data,
  columns = names(data),
  orderByLeastLevels = TRUE,
  as.data.frame = TRUE,
  useNA = c("no", "ifany", "always")[2]
)

Arguments

data

data frame

columns

columns of data to be included in the frequency analysis. Default: all columns of data

orderByLeastLevels

if TRUE (default) the list elements in the output list each of which represents one column of data or the sections of rows in the output data frame are orderd by length(unique(data[[column]]))

as.data.frame

if TRUE (default) the result is a data frame, otherwise a list (see below)

useNA

passed to table see there. Default: "ifany"

Value

for as.data.frame = FALSE a list of data frames each of which represents the frequency statistics for one column of data. Each data frame has columns column (name of the column of data), value (value occurring in column of data), count (number of occurrences). For as.data.frame = TRUE one data frame being the result of rbind-ing together these data frames.

Examples

# Some example data
(data <- data.frame(
  A = c("a1", "a2", "a1", "a1", "a2", "", "a2", NA, "a1"),
  B = c("b1", "b1", NA, "b2", "b2", "b1", " ", "b3", "b2")
))

frequencyTable(data) # results in a data frame

frequencyTable(data, as.data.frame = FALSE) # results in a list


KWB-R/kwb.utils documentation built on April 1, 2024, 7:12 a.m.