0
tenancy <- main_tenant%>%
           group_by(`Tenancy Type`)%>%
           summarise(num = length(`Tenancy Type`), 
                     total = sum(`Number of Works Order`))

I'm trying to get this code to count the amount of different Tenancy Types and for each one sum up the number of works orders for each tenancy type. So I want it to output as:

Tenancy Type    Num      Total
Tenancy1         121       543
Tenancy2         195       323
Tenancy3         1900      5000

And so forth. With the code above the column Num is populated but the column Total all says NA. What am I doing wrong? I thought it was a quite straight forward piece of code!

jazzurro
  • 23,179
  • 35
  • 66
  • 76
MLPNPC
  • 454
  • 5
  • 18
  • 3
    You probably have `NA`s in your `Number of Works Order` column, try `sum(..,na.rm=T)`. – Lamia May 10 '17 at 13:36
  • I'm not sure how to write a table in my question bit on Stack Overflow, I think I'll try and figure out how to do that and it will help, Because the dataframe is beyond large. – MLPNPC May 10 '17 at 13:38
  • @Lamia that's worked thank you!! I knew it would be something small like that, I'm still a beginner to R sorry, hopefully I'll get better at it. – MLPNPC May 10 '17 at 13:39

0 Answers0