0
votes

I have been having a problem with two data frames that I want to merge. One is larger than the other but they share common column names and rownames.

What I would like to do is merge both of them by their specific elements in each row and column.

For example I have 1 data frame: row.names-US Bond,US Stock,EU Bond,EU Stock,Asia Bond,Asia Stock,col.names-Price Risk,Credit Risk,Market Risk;

The other data frame: row.names-US Bond,US Stock;col.names-Price Risk;

Ideally, I would like to merge both data sets by their unique row name and column name.

Sample:

dat1<-matrix(' ',nrow=4,ncol=6)
colnames(dat1)<-c("Value","Percentage","Credit.Risk","Interest.Risk","Interest.Credit.Risk","Total")
rownames(dat1)<-c("Low.Gov.Debt","Low.Corp.Debt","High.Gov.Debt","High.Corp.Debt")
new<-portfolio
rownames(new)<-c("High.Gov.Debt","Low.Gov.Debt")
colnames(new)<-c("Value")
1
Welcome to Stack Overflow! You would make ik a lot easier for others to help you, if you provide a reproducable example - Jaap
start with ?merge, if that doesn't answer your question, give us a dput of some of the data - JeremyS
I have already tried merge and plyr and it doesn't work. It just mixes the data in a very uncovential way. - starter123

1 Answers

1
votes

You need to specify that you're matching by row.names

merge(d1,d2,by="row.names")