title: ifelse r - x and y lengths differ
body: <p>I'm trying to use an <code>ifelse</code> on an array called "OutComes" but it's giving me some trouble.</p>
  
  <pre><code>&gt;  PersonNumber Risk_Factor OC_Death OnsetAge Clinical CS_Death Cure AC_Death
  &gt;[1,]            1           1 99.69098       NA       NA       NA   NA       NA
  &gt;[2,]            2           1 60.68009       NA       NA       NA   NA       NA
  &gt;[3,]            3           0 88.67483       NA       NA       NA   NA       NA
  &gt;[4,]            4           0 87.60846       NA       NA       NA   NA       NA
  &gt;[5,]            5           0 78.23118       NA       NA       NA   NA       NA
  </code></pre>
  
  <p>Now I will try to use an apply to analyse this table's <code>Risk_Factor</code> Column and apply one of two functions to replace the OnsetAge column's NA's.</p>
  
  <p>I've been using an <code>apply</code> function -</p>
  
  <pre><code>apply(OutComes, 1, function(x)ifelse(OutComes[,"Risk_Factor"] == 1, 
                                        HighOnsetFunction(x), OnsetFunction(x))
  </code></pre>
  
  <p>However this obviously won't work as the ifelse itself won't work. the error being -</p>
  
  <blockquote>
    <p>Error in xy.coords(x, y) : 'x' and 'y' lengths differ</p>
  </blockquote>
  
  <p>I'm not sure what's going on in this ifelse or what the x and y lengths are.</p>