Learn R Programming

vcdExtra (version 0.9.6)

as_caseform: Convert frequency or table form into case form.

Description

Converts object (obj) in frequency or table form into case form. The column containing the frequencies (freq) must be supplied if obj is in frequency form. Returns a tibble if tidy is set to TRUE.

Usage

as_caseform(obj, freq = "Freq", dims = NULL, tidy = TRUE)

Value

object in case form.

Arguments

obj

Object to be converted to case form.

freq

If obj is in frequency form, this is the name of the frequency column. If obj is in any other form, do not supply an argument (see "Details").

dims

A character vector of dimensions. If not specified, all variables apart from freq will be used as dimensions.

tidy

Returns a tibble if set to TRUE.

Author

Gavin M. Klorfine

Details

A wrapper for expand.dft that is able to handle arrays.

If a frequency column is not supplied, this function defaults to "Freq" just like expand.dft. Converts obj to a table using as_table before converting to case form.

See Also

as_table, as_freqform, as_array, as_matrix, expand.dft

Examples

Run this code
library(vcdExtra)

data("HairEyeColor")

freqForm <- as.data.frame(HairEyeColor) # Generate frequency form data
tidy_freqForm <- dplyr::as_tibble(HairEyeColor) # Generate tidy frequency form data
tableForm <- as_table(HairEyeColor) # Generate table form data
arrayDat <- as_array(HairEyeColor) # Generate an array

# Frequency form -> case form
as_caseform(freqForm) |> str()

# Frequency form (tibble) -> case form
as_caseform(tidy_freqForm, freq = "n") |> str()

# Array -> case form
as_caseform(arrayDat) |> str()

# Optionally specify dims
as_caseform(tableForm, dims = c("Hair", "Eye")) |> str()


Run the code above in your browser using DataLab