Issue
I need to merge two datasets. The first dataset is the original one that I am working with and the second has data that I need to add. I would merge them based on the company name because that character variable is in both datasets, but they're presented differently (e.g. "Apple Inc." in one data frame and "Apple" in the other) and so I can't just use merge()
like I otherwise would.
I think the best way is to try merge them based on these variables having the first x number of letters in common, but I don't know how to do this, nor do I know if this is even the best way to go about this.
Can anyone please help me with this? I have only been using R for a few months and don't have a programming background so this stuff doesn't come naturally to me.
Solution
A simple workaround would be to add a column with only the substring and use it for merging:
x$merge.col <- substr(x$company.name, 1, 5)
y$merge.col <- substr(y$company.name, 1, 5)
z <- merge(x, y, by="merge.col")
Answered By - cdalitz Answer Checked By - Candace Johnson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.