Skip to contents

NOTE: This function is currently experimental and shouldn't be relied upon.

frequency_grid_df() takes a vector and creates an extended frequency table about it. Internally, this is used as a basis for frequency_grid_plot().

Usage

frequency_grid_df(x, max_unique = NULL)

Arguments

x

A vector.

max_unique

Numeric or string. If the maximum number of unique values in x is known, set max_unique to that number. This rules out that NAs represent values beyond that number (see examples). Set it to "known" instead if no values beyond those already known can occur. Default is NULL, which assumes no maximum.

Value

A data frame with these columns:

  • x: The input vector, with each unique known value repeated to be as frequent as the most frequent one.

  • freq (integer): Hypothetical frequency of each x value.

  • is_missing (logical): Is the observation absent from the input vector?

  • can_be_filled (logical): Are there enough NAs so that one of them might hypothetically represent the x value in question, implying that there would be at least as many observations of that value as the respective frequency (freq) indicates?

  • is_supermodal (logical): Is the frequency of this value greater than the maximum frequency among known values?

Limitations

See the limitations section of frequency_grid_plot().

Examples

x <- c("a", "a", "a", "b", "b", "c", NA, NA, NA, NA, NA)
frequency_grid_df(x)
#>   x freq is_missing can_be_filled is_supermodal
#> 1 a    1      FALSE         FALSE         FALSE
#> 2 a    2      FALSE         FALSE         FALSE
#> 3 a    3      FALSE         FALSE         FALSE
#> 4 b    1      FALSE         FALSE         FALSE
#> 5 b    2      FALSE         FALSE         FALSE
#> 6 b    3       TRUE          TRUE         FALSE
#> 7 c    1      FALSE         FALSE         FALSE
#> 8 c    2       TRUE          TRUE         FALSE
#> 9 c    3       TRUE          TRUE         FALSE