I want to generate how many1s and 0s occur for each year say 2017,2018 and 2019.
            Asked
            
        
        
            Active
            
        
            Viewed 34 times
        
    -1
            
            
         
    
    
        Jimi13 ABC
        
- 19
- 7
- 
                    1Are you just asking how to do `sum(my_array$paying_customers ==0)` ? I think you will benefit by reading R-introductory tutorials – Carl Witthoft Jan 23 '23 at 16:13
- 
                    1Please [do not post code or data in images](https://meta.stackoverflow.com/q/285551/2372064). Share data in a [reproducible format](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so we can copy/paste into R for testing. – MrFlick Jan 23 '23 at 16:24
- 
                    `dplyr::count(df, Year, paying_customers)` will give the number of 1's and 0's for each Year. – Jon Spring Jan 23 '23 at 17:39
1 Answers
1
            
            
        quux <- data.frame(year = c(rep(2017, 5), rep(2018, 4)), paying = c(0,0,1,0,2,0,0,1,1))
quux
#   year paying
# 1 2017      0
# 2 2017      0
# 3 2017      1
# 4 2017      0
# 5 2017      2
# 6 2018      0
# 7 2018      0
# 8 2018      1
# 9 2018      1
table(quux$year, quux$paying > 0)
#       
#        FALSE TRUE
#   2017     3    2
#   2018     2    2
addmargins(table(quux$year, quux$paying > 0), 1)
#       
#        FALSE TRUE
#   2017     3    2
#   2018     2    2
#   Sum      5    4
 
    
    
        r2evans
        
- 141,215
- 6
- 77
- 149

