title: Calculate a new matrix with multiple possible outcomes from pre-existing variables
body: <p>I need to overlay two large matrices (or columns from a merger of the two) to generate a final matrix for analysis. I have a series of points where counts were made 3 times per year for a number of year (generating e.g. counts 2000_1, 2000_2, etc.), but sometimes a point wasn’t done for one reason or another. If the point was done, there may have been detections or there may not. So there are essentially three possible results for each cell in the final matrix to be calculated from the other two values. If no sampling occurred at the point on an occasion, I need the value “.”; if sampling occurred but no detections occurred, I need a “0”, and if sampling occurred and 1-n individuals were detected, I need a “1”. </p>
  
  <p>In the sample data below, I’ve combined the two matrices to simplify but note that the actual datasets would be about 750 records over 64 columns. In column 1, the point ID is provided. The next 5 columns (pt.x) provide whether a count was conducted in a given year_rotation, and the last 5 how many if any detections. An NA is no data, and should only occur when sampling didn’t occur, but could happen if there was sampling but no zero was entered.</p>
  
  <p>Sample</p>
  
  <pre><code>Point &lt;- c(“A194”,” A234”,”A83”,” K37”,” TS47”)
  p0.1 &lt;- c(1,1,1,1,0)
  p0.2 &lt;- c(1,1,1,1,0)
  p0.3 &lt;- c(1,1,1,1,0)
  p1.1 &lt;- c(1,0,1,0,0)
  p1.2 &lt;- c(1,0,1,1,0)
  d0.1 &lt;- c(1,0,0,3,NA)
  d0.2 &lt;- c(0,0,2,2,NA)
  d0.3 &lt;- c(0,0,0,1,NA)
  d1.1 &lt;- c(0,NA,0,NA,NA)
  d1.2 &lt;- c(0,NA,0,0,NA)
  </code></pre>
  
  <p>And here's what I'd like to end up with:</p>
  
  <pre><code>Point f0.1 f0.2 f0.3 f1.1 f1.2
  A194    1    0    0    0    0
  A234    0    0    0    .    .
  A83    0    1    1    0    0
  K37    1    1    1    .    1
  TS47    .    .    .    .    .
  </code></pre>
  
  <p>Can anyone suggest a clean, general way to do this so that it is transferrable to the larger dataset or, ultimately to other similar datasets? I can either start with this scenario, with points and detections (p and d columns above) in the same dataframe, or with two frames, one for each condition. 
  Thanks for your help, and sorry if there are format issue with my post. Relatively new to formatting such.</p>