Learn R Programming

cat2cat (version 0.4.7)

cat_apply_freq: Applying frequencies to the object returned by the `get_mappings` function

Description

applying frequencies to the object returned by the `get_mappings` function. We will get a symmetric object to the one returned by the `get_mappings` function, nevertheless categories are replaced with frequencies. Frequencies for each category/key are sum to 1, so could be interpreted as probabilities.

Usage

cat_apply_freq(to_x, freqs)

Value

a `list` with a structure like `to_x` object but with probabilities for each category.

Arguments

to_x

`list` object returned by `get_mappings`.

freqs

`data.frame` object like the one returned by the `get_freqs` function.

Examples

Run this code
data("trans", package = "cat2cat")
data("occup", package = "cat2cat")

mappings <- get_mappings(trans)

mappings$to_old[1:4]
mappings$to_new[1:4]

mapp_p <- cat_apply_freq(
  mappings$to_old,
  get_freqs(
    occup$code[occup$year == "2008"],
    occup$multiplier[occup$year == "2008"]
  )
)
head(data.frame(I(mappings$to_old), I(mapp_p)))
mapp_p <- cat_apply_freq(
  mappings$to_new,
  get_freqs(
    occup$code[occup$year == "2010"],
    occup$multiplier[occup$year == "2010"]
  )
)
head(data.frame(I(mappings$to_new), I(mapp_p)))

Run the code above in your browser using DataLab