starting to use R in my data analysis, but still a relative newbie. I have a data frame that looks like this:
locations
loc IDnum
100000001 1
100000009 7
100000021 3
100000004 2
100000017 3
100000007 7
100000067 5
and a matrix with a list of the ID numbers (from the second column) and the corresponding strings (like a translation table of sorts).
Looks similar to this:
names
IDnum IDnames
1 NNW43
2 N3
3 SE21
4 SW54
5 W6
6 W12
7 NE10
...
So this matrix is shorter because each ID number has a corresponding string, but in the original data frame there are more than one loc that contain the same IDnum.
I'm sure there is an easy way to match up each ID number with a string and create a new data frame with the first column the same but the second containing the strings instead of ID numbers, but I'm not sure what it is. All I know is that I'm told if you use loops in R you're doing it wrong.
Result would be something like
loc name
100000001 NNW43
100000009 NE10
100000021 SE21
100000004 N3
100000017 SE21
100000007 NE10
100000067 W6
I had a hard time figuring out how to title this question so any input on that would be useful as well. Thanks in advance!
EDITED to provide reproducible example
` and format your code just like I already did? Anyway, just try something like `merge(df1, df2, by = "IDnum", all.x = TRUE)` – David Arenburg Jul 23 '15 at 20:51