How to add rows with 0 counts to summarised output

后端 未结 2 1991
温柔的废话
温柔的废话 2020-12-11 12:37

I have added sample data below, I have used dplyr to count on Rco and month:

structure(list(Rco = structure(c(1L, 1L, 1L, 1L, 2L, 2         


        
2条回答
  •  臣服心动
    2020-12-11 12:50

    You can use tidyr::complete and specify the fill to be 0 (instead of the default NA):

    library(tidyr)
    complete(df, Rco, month, fill = list(count = 0))
    

提交回复
热议问题