title: R output tukey results only where factors or interactions are significant (conditional statements)
body: <p>I'm relatively new to the R language, and using it to analyse my data. I am using a package called 'agricolae' and its HSD.test component to output tukeyHSD results based on the anova proceeding it. I have simplified the code below, but essentially the tukey code is run inside a for loop running through a list of factors/interactions. It works fine, however, I only want the loop to run where the anova result for the corresponding factor is significant. (i.e. &lt;= 0.05).</p>
  <pre><code>f1 &lt;- as.formula(paste(m,'~ Treatment + Genotype + GENOTYPExTREATMENT', sep = ''))
  anova.result &lt;- aov(f1, data = licor.data2)
  
  treatment.list &lt;- c('Treatment','Genotype', 'GENOTYPExTREATMENT')
          
  for(t in treatment.list){ 
     tukey.result &lt;- HSD.test(anova.result, trt = t)$groups
  }
  
  </code></pre>
  <p>using <code>rownames(summary(anova.result)[[1]])</code>
  returns <code>[1] &quot;Treatment         &quot; &quot;Genotype          &quot; &quot;GENOTYPExTREATMENT&quot; &quot;Residuals        &quot;</code>
  and <code>str(summary(anova.result)[[1]])</code> returns:</p>
  <pre><code>Classes ‘anova’ and 'data.frame':   4 obs. of  5 variables:
   $ Df     : num  4 6 24 99
   $ Sum Sq : num  0.01215 0.0019 0.00255 0.00527
   $ Mean Sq: num  3.04e-03 3.16e-04 1.06e-04 5.33e-05
   $ F value: num  57.02 5.94 1.99 NA
   $ Pr(&gt;F) : num  7.22e-25 2.50e-05 9.68e-03 NA
  </code></pre>
  <p>Just wondering if someone knows how to construct a <code>when</code> or <code>if/else</code> statement which will only   run the loop code where the $Pr(&gt;F) value for the corresponding 't' loop factor or interaction is less than 0.05.</p>
  <p>thanks in advance,</p>
  <p>Luke</p>