I am trying to use the merge function in R. I have a list of column names (Stock names) in some data frame D. I then have another data frame 'Info' where these Stock names are stored in a column, with a corresponding sector name in the next column. I need to merge these sector names to a row in D.
If I were merging on 2 columns, I could use merge() directly and alter by.x and by.y and the emrged values would appear as extra columns. However, D has the name I am merging by as its column names, so I essentially want it to add on extra rows? The following code didn't work:
M<-merge(D,Info[,c("Name","Sector")],by.x=colnames(D), by.y=c("Name"))
P.S I have searched around on SO, but nobody has precisely this problem. They have similar ones, but those approaches are not valid for this.