gdemin / expss

expss: Tables and Labels in R
https://cran.r-project.org/web/packages/expss/
84 stars 16 forks source link

Question about net #93

Closed robertogilsaura closed 2 years ago

robertogilsaura commented 2 years ago

Hi @gdemin

I'm processing a product test. In this table, I need to hide (not display but compute in %) a category using net

My code...

data <- data.frame(reTEST=c(1,2,1,2,1,2,1,2,1,2,1,2,1,2), value=c(1,5,4,3,2,1,2,1,5,5,1,1,3,5))
data %>% 
    tab_cols('|'=unvr(reTEST)) %>% 
    tab_cells('|'=unvr(value)) %>% 
    tab_net_cells("Top Box (seguro compraría)" = 5, 
      "Top 2 Box (seguro y probable compraría)"= 4:5, 
      "Bottom 2 Box (seguro y probable no compraría)"=1:2, 
      "Rest"=hide(3)) %>%
    tab_stat_cpct(total_row_position = 'none') %>% 
    tab_cells('|'=unvr(value)) %>% 
    tab_stat_mean() %>% 
    tab_pivot()

I would need that category "Rest" don't display in table. I think that hide() and unhide() don't build the crosstab like I expect, without category Rest (3).

Is there anyway for this?

Thanks in advance, Gregory.

gdemin commented 2 years ago

Hi, @robertogilsaura hide is for "hiding" items from which category consists. So it is applicable only for "subtotal" and absolutely useless for "nets". "nets" hide subitems by default.

In your case it is easier just remove row:

data %>% 
    tab_cols('|'=unvr(reTEST)) %>% 
    tab_cells('|'=unvr(value)) %>% 
    tab_net_cells("Top Box (seguro compraría)" = 5, 
                  "Top 2 Box (seguro y probable compraría)"= 4:5, 
                  "Bottom 2 Box (seguro y probable no compraría)"=1:2, 
                  "Rest"=3) %>%
    tab_stat_cpct(total_row_position = 'none') %>% 
    tab_cells('|'=unvr(value)) %>% 
    tab_stat_mean() %>% 
    tab_pivot() %>% 
    rows(!grepl("Rest", row_labels)) %>% 
    as.etable()
robertogilsaura commented 2 years ago

Thanks a lot for your answer, @gdemin.