I modified your code and invented a small data frame to test it. Does this version work for you? Notice I changed the operator after kids, the order of the arguments in fct_recode and I added a pipe before count().
set.seed(123)
kids <- data.frame(arac = sample(c("0","1","2","3","4","6"), 12, replace = TRUE),
stringsAsFactors = TRUE)
levels (kids$arac)
#> [1] "0" "1" "2" "3" "4" "6"
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(forcats)
kids %>%
mutate(fct_recode(arac,
"No" = "0",
"No" = "1",
"No" = "6",
"YES" = "2",
"YES" = "3",
"YES" = "4")
) |>
count(arac)
#> arac n
#> 1 0 1
#> 2 1 2
#> 3 2 3
#> 4 3 1
#> 5 4 1
#> 6 6 4
Hi,
Thanks for your help
I should change the pipe from |> to %>% to make the code work. I do not why..
However I get the same levels and not the "YES", "NO" merge