R- merging two data frames

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")

Answers


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

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

Need Your Help

Sorting an NSArray by a key-value relationship that is 2 levels deep

objective-c cocoa-touch sorting nsarray userinfo

I have an NSArray of UILocalNotification objects that I need to sort according to a key within the UILocalNotification's userInfo property, which is an NSDictionary. I know how to sort NSArrays by a