I am trying to add a column to the end of the data frame with the level of each MSCI.ESG.Rating but I just can't figure it out.
sub <- subset(fsdf, select = c(BBG_Ticker, MSCI.ESG.Rating, esg))
sub$MSCI.ESG.Rating <- sub$MSCI.ESG.Rating %>% trimws(which = "both")
levels(sub$MSCI.ESG.Rating) <- list("5"=c("AAA", "A"), "4"="A","3"="BBB","2"="BB","1"=c("B", "CCC"))
sub <- sub %>% mutate(esgq = ntile(sub$esg, 5)) %>% mutate(msciq = levels(sub$MSCI.ESG.Rating))