title: Finding the max in an R vector using a for loop, without using max()
body: <p>How do I find the max in an R vector using a for loop, without using max()?</p>
  
  <p>Here is my solution:</p>
  
  <pre><code>a=c(-9,20,40,1,5,0)
  y=-Inf
  z=0
  
  for (i in a) {
  x=i
  if(x&gt;y){y=i}
  else{y=Inf}
  if(y!=-Inf &amp; z&lt;y){z=i}
  }
  print(paste0("maximum number is:" , z))
  </code></pre>
  
  <p>Is there a simpler way to do it?</p>