Let I have such data frames(df1 and df2):
df1
ID y
4 12
2 65
3 7
5 878
1 1
7 122
df2
ID z
2 90
5 16
1 22
In df2 the ID's are also avaible in df1. Namely df2 is subset of df1 in terms of ID column.
I want create a new data frame(df3) such that
ID y
4 12
2 90
3 7
5 16
1 22
7 122
Namely, in df1 y values are replaced with z values in df2 for the common ID's.
How can do that using R? I will be vet glad for any help. Thanks a lot.
within(merge(df1, df2, all = TRUE), { y[!is.na(z)] <- na.omit(z); rm(z) }), but the row order will be different - Rich Scriven