I couldn't find another question that would answer this one so here it is :
I have a data.frame
(lets say nodes
) in which are stored nodes attributes, one column is the node's ID and all other columns are the node's attributes.
I have a second data.frame
(lets says def
) where combinations of my nodes attributes are matched to a value.
What I am trying to do is add a new column/attribute to nodes
so that combinations of nodes
data.frame
are matched to the values defined in def
.
It basically would look like that
> nodes
Attr1 Attr2 Attr3
1 1 1
2 1 2
1 3 1
3 2 1
and
> def
Attr1 Attr3 Res
1 1 1
1 2 2
2 1 3
2 2 4
And should return
> nodes
Attr1 Attr2 Attr3 Res
1 1 1 1
2 1 2 4
1 3 1 1
1 2 1 2
For now, I am thinking of using split
to subset my data.frame
into multiple data.frames
each corresponding to a combinations of my factors of interest and then giving to the proper rows the proper values but I have some problem with that method :
- If there are lots attributes
split
is gonna take a real long time - How would I put my
data.frame
back in one piece ? - It does not sound elegant at all
So is there another way to do that ? And if not how would I build back my data.frame ?
Thanks