This is my df:
JU_FINANCIAMENTO PRE CRE MERITO_AUTOMATICO
1 0 1 0 0
2 0 0 1 0
3 0 1 0 0
4 1 0 0 0
5 0 1 0 0
6 0 0 0 1
I need to create a new column with the name of the column where the number 1 is presented, as follows
JU_FINANCIAMENTO PRE CRE MERITO_AUTOMATICO NEW_COLUMN
1 0 1 0 0 PRE
2 0 0 1 0 CRE
3 0 1 1 0 PRE
4 1 0 0 0 JU_FINANCIAMENTO
5 0 1 0 0 PRE
6 0 0 0 1 NA
What I tried so far:
for (i in names(df)) {
df <- df %>%
mutate(NEW_COLUMN = ifelse(i == 1, paste(i), "NAN"))
}
But i got this: Error: Can't bind data because some arguments have the same name