我想算出每年有多少个1和0,比如2017年,2018年和2019年。
ui7jx7zq1#
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
1条答案
按热度按时间ui7jx7zq1#