title: Assigning within a lapply "NAs are not allowed in subscripted assignments"
body: <p>I am trying to recode, and am running into a snag that seems simple enough, but I haven't been able to figure out after quite some time asking the internet, so I appreciate any help you can give.</p>
  
  <p>I have some data that contains NA's.  I would like to recode, using this data, but keep on running into the error "NAs are not allowed in subscripted assignments." As I'm trying to create an example data set, I'm additionally running into a warning that I don't have "meaningful factors." Any help would be appreciated.</p>
  
  <p>My faux-data has three variables: "var1" and "var2" (character, and sometimes missing) and "var3" (numeric). I want to create a fourth variable, that contains the value of "var1" if beta is greater than zero, and contains the value of "var2" if beta is less than zero. If var1 or var2 is missing, I want the new variable to also be missing:</p>
  
  <pre><code>var1&lt;-c("A","T",NA,"G","C")
  var2&lt;-c("G","A",NA,"A","G")
  var3 &lt;-c(-.1,3,-4,5,-3)
  df=as.data.frame(cbind(var1,var2,var3))
  
  df$newVar[df$var3&gt;0]=df$var1[df$var3&gt;0]
  df$newVar[df$var3&lt;0]=df$var2[df$var3&lt;0]
  </code></pre>
  
  <p>What I get is a bunch of red:</p>
  
  <pre><code>df$newVar[df$var3&gt;0]=df$var1[df$var3&gt;0]
  Error in df$newVar[df$var3 &gt; 0] = df$var1[df$var3 &gt; 0] : 
  NAs are not allowed in subscripted assignments
  In addition: Warning messages:
  1: In Ops.factor(df$var3, 0) : &gt; not meaningful for factors
  2: In Ops.factor(df$var3, 0) : &gt; not meaningful for factors
  df$newVar[df$var3&lt;0]=df$var2[df$var3&lt;0]
  Error in df$newVar[df$var3 &lt; 0] = df$var2[df$var3 &lt; 0] : 
  NAs are not allowed in subscripted assignments
  In addition: Warning messages:
  1: In Ops.factor(df$var3, 0) : &lt; not meaningful for factors
  2: In Ops.factor(df$var3, 0) : &lt; not meaningful for factors
  </code></pre>
  
  <p>Any advice would be appreciated. Thank you.</p>