[R] A question on data frame

Christofer Bogaso bogaso.christofer at gmail.com
Wed Aug 24 20:48:16 CEST 2016


Hello again,

Let say I have a data.frame which I call as reference data frame :

Ref = data.frame(c("a", "d", "c", "e", "f", "x"), matrix(NA, 6, 5))
colnames(Ref) = c("a1", "a2", "a3", "a4", "a5", "a6")
Ref

Now I have another data.frame, which I call as value data frame :

Value = data.frame(c("x", "c"), matrix(1:10, 2, 5))
colnames(Value) = c("a1", "b2", "b3", "b4", "b5", "b6")
Value

Now I need to insert the values of my 'Value' data frame into my 'Ref'
data frame, according to the order of the column of 'a1' of 'Ref'.

For example, the NA values of last row of Ref will be (1,  3,  5,  7,
9) and 3rd row of Ref will be (2,  4,  6,  8, 10). Basically I am
matching the "a1" column of both my data frames. If there is no match
found then corresponding row of Ref will remain unchanged.

Is there any R way to perform the same programmatically. In reality
both my data frames are quite big, so looking for some automated way
to perform the same.

Thanks for your time.

Regards,



More information about the R-help mailing list