i have two dataframes, the first shows the returns
year <- c(2013:2017)
a <- c(0.0125, 0.0045, -0.0102, 0.0023, -0.0011)
b <- c(0.0267, 0.0005, 0.0922, -0.0510, 0.0389)
c <- c(-0.0045, 0.0023, 0.0426, 0.0201, -0.0291)
d <- c(0.0119, -0.0131, 0.0189, 0.0192, 0.0111)
e <- c(-0.0279, 0.0255, 0.0059, 0.0059, 0.0223)
f <- c(0.0479, 0.0345, -0.0145, -0.0001, 0.0000)
g <- c(0.0352, 0.0165, 0.0004, 0.0055, -0.0050)
return.df <- data.frame(year,a,b,c,d,e,f,g)
and the second daraframe looks like this and shows the character
year <- c(2013:2017)
data1 <- c("c","a","g","d","e")
data2 <- c("b","f","a","e","d")
data3 <- c("f","b","c","d","e")
data4 <- c("e","a","d","b","c")
data5 <- c("d","e","c","b","a")
character.df <- data.frame(year,data1,data2,data3,data4,data5)
now i want to show in a new dataframe the returns, they're related to the character.
for example, in the first row the year 2013 it should show instead of the character "c" the return from character "c" in 2013, in this case -0.0045 and so on. the new dataframe should be
2013 -0.0045 0.0267 0.0479 -0.0279 0.0119
2014 0.0045 0.0345 0.0005 0.0045 0.0255
2015 0.0004 -0.0102... and so on
hope you know what i mean. i tried it with "merge" but could not find the solution..
thank you very much