R - Merging data.frames in the same column containing NAs
===

I have four data.frames which all have the same columns, being the first the same to all. In the variable columns there are some NAs.

First, I'd like to replace any value (which is not an NA) in each data.frame by the name of the data.frame.
Second, I'd like to merge the data.frames. In this case, for each NA, there will be some other data.frame which would have a value for it, so that I'd end with every cell filled with values (or names of the data.frames).


Here's an example with two data.frames:

     >A
     name Q  W  E  R  T
     g1   NA NA 4  NA 0
     g2   3  2  NA 4  5
     g3   NA 1  NA 0  0
     g4   0  NA NA 1  9
     
     >B
     name Q  W  E  R  T
     g1   2  4  NA 1  NA
     g2   NA NA 5  NA NA
     g3   5  NA 0  NA NA
     g4   NA 6  4  NA NA

     >result
     name Q  W  E  R  T
     g1   B  B  A  B  A
     g2   A  A  B  A  A
     g3   B  A  B  A  A
     g4   A  B  B  A  A

I've tried some merge() and union() options differently. Also, I've tried to adapt answers to similar questions but I can't seem to solve this. 

http://stackoverflow.com/questions/8349909/creating-a-function-to-replace-nas-from-one-data-frame-with-values-from-another

http://stackoverflow.com/questions/5871916/merging-data-frames-with-missing-values-in-r?rq=1

Thank you in advance!