r - How to transfer variable value from one dataframe to another dataframe by two conditions? -
i have 2 data follows. want transfer value of change in first dataframe second dataframe date , code.
> date code change 1 2013-12-27 000586 0.990099012851715 2 2013-12-26 000616 9.97067451477051 3 2013-12-25 300295 10.0013799667358 4 2013-12-23 000968 -8.1564245223999 5 2013-12-19 600023 60.5786628723145 6 2013-12-18 600855 -7.69696950912476 > b code date company 1 000586 2013-12-27 2 000616 2013-12-26 b 3 300295 2013-12-25 c 4 000968 2013-12-23 d 5 600023 2013-12-19 6 600023 2013-12-19 b 7 600855 2013-12-18 c
the final result should like:
> c code date company change 1 000586 2013-12-27 0.990099012851715 2 000616 2013-12-26 b 9.97067451477051 3 300295 2013-12-25 c 10.0013799667358 4 000968 2013-12-23 d -8.1564245223999 5 600023 2013-12-19 60.5786628723145 6 600023 2013-12-19 b 60.5786628723145 7 000586 2013-12-27 b 0.990099012851715
how can this?
instead of creating new dataframe, can add new column b
dataframe match
:
b$change <- a$change[match(b$code,a$code)]
Comments
Post a Comment