I have a data.frame
df1=data.frame(f=LETTERS[1:4],v=c(1:4))
f v
1 A 1
2 B 2
3 C 3
4 D 4
The first column is a list of factors, in which I have another data frame that houses these values, which are also factors
df2=data.frame(f=LETTERS[1:7],f2=letters[26:20])
f f2
1 A z
2 B y
3 C x
4 D w
5 E v
6 F u
I am wondering how to write a function so that I can alter the values from the first column of df1 to what they map to from df2. I would like to get:
f v
1 z 1
2 y 2
3 x 3
4 w 4
I tried a for loop with no success. Ant suggestions is greatly appreciated
Note: this is a simplified example of my work. A merge would add too many columns to work with and I don't think the extra memory storage would be very useful