title: R, getting an invalid argument to unary operator when using order function
body: <p>I'm essentially doing the exact same thing 3 times, and when adding a new variable I get this error </p>
  
  <pre><code>Error in -emps$EV : invalid argument to unary operator
  </code></pre>
  
  <p>The code chunk causing this is </p>
  
  <pre><code>evps&lt;-aggregate(EV~player,s1k,mean)
  sort2&lt;-evps[order(-evps$EV),]
  head(sort2,10)
  
  s1k$EM&lt;-s1k$points-s1k$EV
  emps&lt;-aggregate(EM~player,s1k,mean)
  sort3&lt;-emps[order(-emps$EV),]
  head(sort3,10)
  </code></pre>
  
  <p>Works like a charm for the first list, but the identical code thereafter causes the error.</p>
  
  <p>This specific line is causing the error</p>
  
  <pre><code>sort3&lt;-emps[order(-emps$EV),]
  </code></pre>
  
  <p>How can I fix/workaround this?</p>
  
  <p>Full Code</p>
  
  <pre><code>url &lt;- getURL("https://raw.githubusercontent.com/M-ttM/Basketball/master/class.csv")
  shots &lt;- read.csv(text = url)
  shots$make&lt;-shots$points&gt;0
  shots2&lt;-shots[which(!(shots$player=="Luc Richard Mbah a Moute")),]
  fit1&lt;-glm(make~factor(type)+factor(period), data=shots2,family="binomial")
  summary(fit1)
  shots2$makeodds&lt;-fitted(fit1)
  shots2$EV&lt;-shots2$makeodds*ifelse(shots2$type=="3pt",3,2)
  shots3&lt;-shots2[which(shots2$y&gt;7),]
  locmakes&lt;-data.frame(table(shots3[, c("x", "y")]))
  
  s1k &lt;- shots2[with(shots2, player %in% names(which(table(player)&gt;=1000))), ]
  
  pps&lt;-aggregate(points~player,s1k,mean)
  sort&lt;-pps[order(-PPS$points),]
  head(sort,10)
  
  evps&lt;-aggregate(EV~player,s1k,mean)
  sort2&lt;-evps[order(-evps$EV),]
  head(sort2,10)
  
  s1k$EM&lt;-s1k$points-s1k$EV
  emps&lt;-aggregate(EM~player,s1k,mean)
  sort3&lt;-emps[order(-emps$EV),]
  head(sort3,10)
  </code></pre>