title: How to replace all negative values in vector by 0 in R
body: <p>I have a randomly generated vector from a normal distribution with 50 elements </p>
  
  <pre><code>vector&lt;-c(rnorm(50)) 
  </code></pre>
  
  <p>I want to change all negative values to 0 and positive values to 1 </p>
  
  <p>I used this function and indexing however then I do not get vector with 50 elements </p>
  
  <pre><code>vector[ vector&lt; 0 ] &lt;- 1
  vector[ vector&gt; 0 ] &lt;- 0
  </code></pre>
  
  <p>How should I proceed? </p>