0

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))
  • You need to make your question reproducible for us: where's this data coming from? Can you run `dput` on your data? – Ben G Sep 14 '22 at 17:41
  • @BenG It's a function that takes the argument fsdf which is a dataframe, is the data important? I'm only trying to add a columns of the levels. – Ruben Varghese Sep 15 '22 at 07:35
  • Yes, it's hard to tell why you're having an issue without seeing the data. or being able to reproduce your problem. See https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Ben G Sep 22 '22 at 13:56

0 Answers0