MatthieuStigler / matPkg

Other
2 stars 0 forks source link

need function to compute overlapping counts with/without totals #32

Open MatthieuStigler opened 5 years ago

MatthieuStigler commented 5 years ago

For now I would do four distinct counts, mutate, and rbind. See below.

Maybe better:

  1. do whole count
  2. now do sums over that one, over Fac1, Fac2, over Fac1 & Fac2
  3. rbind all

Old colde:

vars_fld_seq_11 <- vars_fld_seq %>% 
  filter(year>2010) %>% 
  filter(!str_detect(seq_4Y, "NA"))

## all, all Cat
coun_seqs_allC_allS <-  vars_fld_seq_11%>%
  count(year, crop, seq_4Y) %>% 
  mutate(st_abb="all", CS_only_cat = "all")

## all, by Cat
coun_seqs_byC_allS <-  vars_fld_seq_11%>%
  count(year, crop, CS_only_cat, seq_4Y) %>% 
  mutate(st_abb="all")

## by state, all cat
coun_seqs_allC_byS <- vars_fld_seq_11 %>%
  count(year, crop,  seq_4Y, st_abb) %>% 
  mutate(CS_only_cat = "all")

## by state, all cat
coun_seqs_byC_byS <- vars_fld_seq_11 %>%
  count(year, crop,  CS_only_cat, seq_4Y, st_abb)

## assemble
coun_seqs_all <- rbind(coun_seqs_allC_allS,
                       coun_seqs_byC_allS,
                       coun_seqs_byC_byS,
                       coun_seqs_allC_byS)