-
Notifications
You must be signed in to change notification settings - Fork 26
Closed
Description
library(tidyverse)
d = tibble(x = ordered(c("apple", "bear", "banana", "dear")))
# works
fct_recode(d$x, fruit = "apple", fruit = "banana")
#> [1] fruit bear fruit dear
#> Levels: fruit < bear < dear
# works when using a new variable
tidylog::mutate(d, y = fct_recode(x, fruit = "apple", fruit = "banana"))
#> mutate: new variable 'y' with 3 unique values and 0% NA
#> # A tibble: 4 x 2
#> x y
#> <ord> <ord>
#> 1 apple fruit
#> 2 bear bear
#> 3 banana fruit
#> 4 dear dear
# fails when overwriting
tidylog::mutate(d, x = fct_recode(x, fruit = "apple", fruit = "banana"))
#> Error in Ops.factor(new, old): level sets of factors are different
# works with factor
d = tibble(x = factor(c("apple", "bear", "banana", "dear")))
tidylog::mutate(d, x = fct_recode(x, fruit = "apple", fruit = "banana"))
#> mutate: changed 2 values (50%) of 'x' (0 new NA)
#> # A tibble: 4 x 1
#> x
#> <fct>
#> 1 fruit
#> 2 bear
#> 3 fruit
#> 4 dearMetadata
Metadata
Assignees
Labels
No labels