Skip to content
Prev 76248 / 398502 Next

better than sapply

I have the following two mapping data frames (r) and (h). I want to
fill teh value of r$seid with the value of r$seid where r$cid==h$cid.
I can do it with sapply as such:
Is ther a better (faster) way to do this?
seid      cid 
1  NA    2181   
2  NA    2221   
3  NA    2222
cid  seid 
1 5598 2219    
2 5609 2222     
3 4931 2181  
4 5611 2190   
5 8123 2817   
6 8122 2221   
  
to get the desired result of:
seid  cid
1 4931 2181
2 8122 2221
3 5609 2222