I have to data frames, returns.df and funds.df with identical dimensions:
returns1 <- c(0.1,0.2,0.5,0.9)
returns2 <- c(0.3,0.4,0.7,0.1)
returns.df <- data.frame(returns1,returns2)
returns.df
funds1 <- c("Fund A","Fund B","","Fund D")
funds2 <- c("Fund B","Fund C","","Fund A")
funds.df <- data.frame(funds1, funds2)
funds.df
I am trying to store 4 subsets of returns for each of the funds. For example, the subset Fund Returns for fund A would look like:
returns.FundA1 <- c(0.1,"","","")
returns.FundA2 <- c("","","",0.11)
returns.FundA.df <- data.frame(returns.FundA1, returns.FundA2)
returns.FundA.df
Basically I want to create a new data.frame where I just replace the Fund name in fund.df separately by its returns in returns.df, but in a new data.frame. Normally I would do this in excel across multiple sheets using a simple if function. But I am confident that this can be done much faster in R. I appreciate any inputs