Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create column based on another dataframe

Tags:

r

I have what seems a simple requirement, but I can't seem to achieve the desired result. My dataframes are rather large, so I will just give a screenshot:enter image description here

What I want is: if ps2c$ps == present2$pn then ps2c$sf == present2$sf.

If it is not clear, for every ps2c$ps there is a present2$pn (present2 is just the mean data).

like image 709
Frank Zafka Avatar asked Apr 11 '11 09:04

Frank Zafka


1 Answers

You don't supply test data, but something like the following might work:

ps2c$sf <- present2$sf[match(ps2c$ps, present2$pn)]
like image 148
Andrie Avatar answered Nov 11 '22 23:11

Andrie