Skip to contents

Match the input factor to supplied levels.

Usage

emend_lvl_match(.f, levels = NULL, chat = get_default_chat())

Arguments

.f

A vector of characters or a factor.

levels

The levels of the factor.

chat

The chat object defined by ellmer.

Value

A named character vector of standardised category labels, with the class "emend_lvl_match". The names correspond to the original messy categories, and the values are the cleaned versions.

Examples

# \donttest{
chat <- ellmer::chat_ollama(model = "llama3.1:8b", seed = 0, echo = "none")
emend_lvl_match(messy$country,
                levels = c("Asia", "Europe", "North America", "Oceania",
                           "South America"),
                chat = chat)
#>              UK              US          Canada  United Kingdom             USA 
#>        "Europe" "North America" "North America"        "Europe" "North America" 
#>     New Zealand              NZ       Australia 
#>       "Oceania"       "Oceania"       "Oceania" 
#> 
#> ── Converted by emend: ─────────────────────────────────────────────────────────
#>         original     converted
#> 1             UK        Europe
#> 2 United Kingdom        Europe
#> 3             US North America
#> 4         Canada North America
#> 5            USA North America
#> 6    New Zealand       Oceania
#> 7             NZ       Oceania
#> 8      Australia       Oceania
# }