title: Error in Apply function: "arguments imply differing number of rows: 1, 0"
body: <p>I have a data frame.  I need to search for column "a", and if "a" equals "foo", column "b" equals "found"</p>
  
  <pre><code>a &lt;- c("foo", "bar", "baz", "foo")
  b &lt;- c(0, 0, 0, 0)
  df &lt;- data.frame(a, b)
  
  f &lt;- function (x){
    if (x["a"] == "foo"){
      x["b"] &lt;- "confirm"
    }
  }
  
  result &lt;- apply(df, 1, f)
  </code></pre>
  
  <p>The intended result is</p>
  
  <pre><code>a        b
  "foo"    "confirm"
  "bar"    0
  "baz"    0
  "foo"    "confirm"
  </code></pre>
  
  <p>but when I do this, result returns: </p>
  
  <pre><code> [[1]]
  [1] "confirm"
  
  [[2]]
  NULL
  
  [[3]]
  NULL
  
  [[4]]
  [1] "confirm"
  </code></pre>
  
  <p>and View(result) gives the error:
      Error in View : arguments imply differing number of rows: 1, 0</p>
  
  <p>Is it adding another dimension to the data frame?</p>