restate {markovmix}R Documentation

Reorganize states in MarkovMix object

Description

restate reorganizes states in MarkovMix object with a function.

Usage

restate(.object, .fun, .check = TRUE, ...)

Arguments

.object

MarkovMix object.

.fun

Function to process each column in state transition patterns as factors, such as those in forcats package.

.check

Logical (1L) indicating whether to check object at the beginning.

...

Additional arguments passed on to .fun.

Value

A MarkovMix object with modified states and count matrix.

Note

Change log:

Author(s)

Xiurui Zhu

See Also

Other MarkovMix utilities: Extract.MarkovMix, get_counts(), get_order(), get_prior(), get_prob(), get_states_mat(), get_states()

Examples

# Load example MarkovMix object
data("markov_mix_ex")

# Reverse states (using function)
markov_mix_new1 <- restate(
  .object = markov_mix_ex,
  .fun = forcats::fct_rev
)
print(markov_mix_new1)

# Reorder states by hand (using function name with additional arguments)
markov_mix_new2 <- restate(
  .object = markov_mix_ex,
  .fun = "levels<-",
  value = c("B", "D", "C", "A")
)
print(markov_mix_new2)

# Merge state D into C (using purrr-style lambda function)
markov_mix_new3 <- restate(
  .object = markov_mix_ex,
  .fun = ~ forcats::fct_recode(.x, "C" = "D")
)
print(markov_mix_new3)

[Package markovmix version 0.1.3 Index]