title: R - using predict function when one variable is a binary factor
body: <p>My linear model is trying to predict the amount gambled based on the variables sex, income, verbal, and status. Sex is a binary variable that is "Male" or "Female" (they are factors), while the rest are all numeric.</p>
  
  <pre><code>lm3 &lt;- lm(gamble ~ sex + status + income + verbal, data=teengamb)
  </code></pre>
  
  <p>That is my linear model. I'm having trouble predicting the function for a male with mean status, income, and verbal:</p>
  
  <pre><code>newdata &lt;- c(as.factor("Male"), mean(teengamb$status), mean(teengamb$income), mean(teengamb$verbal))
  newdata &lt;- data.frame(newdata)
  predict(lm3, newdata) 
  </code></pre>
  
  <p>I'm not sure how to go about doing this.</p>
  
  <p>Note that the way I converted it to Male and Female is:</p>
  
  <p>However, I have converted the 0=male, 1=female to "Male" and "Female."</p>
  
  <pre><code>teengamb$sex[teengamb$sex==0] &lt;- "Male"
  teengamb$sex[teengamb$sex==1] &lt;- "Female"
  teengamb$sex &lt;- as.factor(teengamb$sex)
  </code></pre>