I am trying to replace a certain 4/5 letter code with a longer name in a dataframe created by the ReShaped melt() function. However, its not working.
What I have at the start (shortened version):
Index Fund Value
1 2021.06.01 VDEE 0.00000000
2 2021.06.02 VDEE -0.04419429
3 2021.06.03 VDEE -0.24161782
4 2021.06.04 VDEE -0.03707800
5 2021.06.07 VDEE 0.56371383
What I want to end up with:
Index Fund Value
1 2021.06.01 FTSEDevelopedEuropeexUKEquityIndexFund 0.00000000
2 2021.06.02 FTSEDevelopedEuropeexUKEquityIndexFund -0.04419429
3 2021.06.03 FTSEDevelopedEuropeexUKEquityIndexFund -0.24161782
4 2021.06.04 FTSEDevelopedEuropeexUKEquityIndexFund -0.03707800
5 2021.06.07 FTSEDevelopedEuropeexUKEquityIndexFund 0.56371383
What I currently end up with:
Index Fund Value
1 2021.06.01 <NA> 0.00000000
2 2021.06.02 <NA> -0.04419429
3 2021.06.03 <NA> -0.24161782
4 2021.06.04 <NA> -0.03707800
5 2021.06.07 <NA> 0.56371383
Basically I want to replace a short code with a longer string in the dataframe. However the main way to do this I have found is: ReShaped[ReShaped == Fund] <- Name
.
But when I do this I get the following error: invalid factor level, NA generated
. Which led me to this. However when I add the stringsAsFactors = FALSE
argument to the melt()
function I still get the error, and the same if I do this ReShaped[ReShaped == Fund] <- factor(Name)
Any Ideas on what the problem is or how to solve it?
Note: I would like to keep the same format of the dataframe as I am then going to plot it in ggplot2.