title: How do I just calculate the average for a specific set of rows in Rstudio
body: <pre><code>DF &lt;- data.frame(Height = rnorm(100, 170, 5),
                   Weight = rnorm(100, 55, 5))
  BMI = function(height,weight){(weight/(height)^2*10000)}
  DF$bmi = BMI(DF$Height,DF$Weight)
  
  DF$weight_group &lt;- 
    cut(
      x = DF$Weight,
      breaks = c(0,60,70,Inf),
      include.lowest = TRUE,
      labels = c(&quot;0-60&quot;, &quot;61-70&quot;, &quot;71+&quot;)
    )
  
  DF$BMI_group &lt;-
    cut(
      x = DF$bmi,
      breaks = c(0, 19.75582, Inf),
      include.lowest = TRUE,
      labels = c(&quot;Below Average&quot;, &quot;Above Average&quot;)
    )
  </code></pre>
  <p>This is my code. I cannot figure out how to just calculate the average of the last half of the data frame. I didn't know how to add in gender, to make 50 males and 50 females, so this is my work around.</p>