title: Error in model.frame.default : variable lengths differ while running ANOVA
body: <p>While running ANOVA analysis on a subset of my dataset this error is displayed:  </p>
  
  <pre><code>  Error in model.frame.default(formula = ready$GDPpercapita[ready$cluster ==  :   variable lengths differ (found for 'ready$GDPpercapita[ready$cluster == 3]')
  </code></pre>
  
  <p>Following is my code:</p>
  
  <pre><code>     for(a in 1:6){
    for(b in a+1:6){
      result=paste("GDPpercapita  CLusters ",a,"&amp;",b)
      print( result)
      first&lt;-subset(ready,ready$cluster==a)
      second&lt;-subset(ready,ready$cluster==b)
      x&lt;-summary(aov(first$GDPpercapita~second$GDPpercapita))
      print(x)
    }
  }
  </code></pre>
  
  <p>And here is a glimpse of my data:</p>
  
  <p><a href="https://i.stack.imgur.com/Vb5lP.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>The error is not because of the loop or because of creating the subsets , as the following code also returns the same error:</p>
  
  <pre><code>x&lt;-summary(aov(ready$GDPpercapita[ready$cluster==1]~ready$GDPpercapita[ready$cluster==2]))
  print(x)
  </code></pre>
  
  <p>The column cluster is a factor variable.
  My objective is to run an ANOVA for every variable(eg GDPpercapita) for all pairs of clusters.</p>
  
  <p>Any help will be appreciated.</p>