Create a column based on another data frame

I have what seems like a simple requirement, but I cannot achieve the desired result. My data is very large, so I just show a screenshot: enter image description here

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

If it’s not clear, for every ps2c$ps there is present2$pn (present2 is just average data).

+4
source share
1 answer

You do not provide test data, but something like the following may work:

 ps2c$sf <- present2$sf[match(ps2c$ps, present2$pn)] 
+8
source

Source: https://habr.com/ru/post/1347512/


All Articles