Hello abhilash!
Hope you are having a good day. I enjoyed your question! Here are some resources if you want to dig a little deeper into the concepts I'm using:
Iteration: http://r4ds.had.co.nz/iteration.html
Strings: http://r4ds.had.co.nz/strings.html
library(tidyverse)
my_tibble <- tibble(
Prod_Des = c("A", "B", "C", "D", "E", "F", "G", "H"),
MF240 = c(rep(FALSE, 2), TRUE, rep(FALSE, 5)),
MF2604H = c(TRUE, rep(FALSE, 7)),
MF2605 = c(FALSE, TRUE, FALSE, TRUE, rep(FALSE, 2), TRUE, FALSE),
MF2605H = c(rep(FALSE, 4), TRUE, rep(FALSE, 2), TRUE),
MF2606H = c(rep(FALSE, 5), TRUE, rep(FALSE, 2))
)
for (i in 1:length(my_tibble)) {
my_tibble[[i]] <- str_replace(my_tibble[[i]], "TRUE", colnames(my_tibble)[i])
}
I also included the code to make your tibble/data frame so that others could easily find other solutions. Have a good one
Best,
fran