can’t transform a data frame with duplicate names mutate() function in tidyverse dplyr

Issue

This Content is from Stack Overflow. Question asked by Hong

Yesterday when I tried to use mutate() function to recode some values in a specific column,everything was fine.
But suddenly, I run these codes again today, it returns errors from the line with mutate() function:

Can’t transform a data frame with duplicate names.

Backtrace:

  1. EVS_recode %>% mutate_at(c(“C001”), ~na_if(., -1))
  2. dplyr::mutate_at(., c(“C001”), ~na_if(., -1))
  3. dplyr:::mutate.data.frame(.tbl, !!!funs)
  4. dplyr:::mutate_cols(.data, …, caller_env = caller_env())
  5. DataMask$new(.data, caller_env)
  6. dplyr:::initialize(…)

here are the codes I used which work perfectly yesterday

#recode the 1 in column C001 to be 5, 2 to be 4#

EVS_recode <- EVS_recode %>% mutate(C001= recode(C001, '1' = 5, '2'= 4))

#recode the -1,-2,-4,-5 values to be NA in column C001#

EVS_recode <- EVS_recode %>% mutate_at(c('C001'), ~na_if(.,-1))

EVS_recode <- EVS_recode %>% mutate_at(c('C001'), ~na_if(.,-2))

EVS_recode <- EVS_recode %>% mutate_at(c('C001'), ~na_if(.,-4))

EVS_recode <- EVS_recode %>% mutate_at(c('C001'), ~na_if(.,-5))

This is my first time to have such large scale of codes not working related to mutate()
Could someone help me or has the similar problem when using mutate() ?

Thanks for your time to read this!
It would be very helpful if someone can give me a hint.



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?