
recode_values() and replace_values() provide two ways to map old values to new values. They work by matching values against x and using the first match to determine the corresponding value in the output vector. You can also think of these functions as a way to use a lookup table to recode a vector. Use recode_values() when creating an entirely new vector. Use replace_values() when partially updating an existing vector. If you are just replacing a few values within an existing vector, then replace_values() is always a better choice because it is type stable and better expresses intent. A major difference between the two functions is what happens when no cases match: recode_values() falls through to a default. replace_values() retains the original values from x. These functions have two mutually exclusive ways to use them: A formula-based approach, i.e. recode_values(x, from1 ~ to1, from2 ~ to2), similar to case_when(), which is useful when you have a small number of cases. A vector-based approach, i.e. recode_values(x, from = from, to = to), which is useful when you have a pre-built lookup table (which may come from an external source, like a CSV file). See vignette("recoding-replacing") for more examples.
@jrosell Ja no es poden fer servir els `!!!` per fer un recode a partir d'un vector, oi?
Suposo que no es pot fer truita sense trencar algun ou. La interfĂcie d'aquesta famĂlia de funcions Ă©s bastant millor que l'anterior penso.
I a més hi ha les versions sense dependències de {vctrs} per utilitzar en paquets.