title: Creating a dataframe in R
body: <p>I created a data frame in r called "test". When I am trying to add a column it  throws me an error. Below is the code i use to create a column:</p>
  
  <pre><code>test$survived[test$sex == "male"] &lt;- 1
  </code></pre>
  
  <p>Error I get:</p>
  
  <pre><code>Error in $&lt;-.data.frame(*tmp*, "survived", value = numeric(0)) : 
  replacement has 0 rows, data has 418
  </code></pre>
  
  <p>I also tried using ifelse but it gives me the same error message. I have just started using R. Would greatly appreciate your help.</p>