jimmyfund
jimmyfund

Reputation: 21

How to fix headers to display label instead of zeros and ones?

In R-studio using expss package to make a table but unlike in the expss example, the headers aren't displaying their labels and area instead displaying zeros and ones.

I've tried using the two different ways to make tables but both give me the same problem.

This first one at least gives me the variable names in the titles:

NESTFH2 %>% tab_cells(FH) %>% tab_cols(Diagnosis.,Strabismus.,Amblyopia.,Glasses) %>% tab_stat_cases() %>% tab_pivot()

table with headers - but subheaders are 0s and 1s

This second one doesn't even give the variable names in the titles:

cro_cases(FH, list(Diagnosis.,Strabismus., Amblyopia., Glasses="Glasses"))

table without even any headers, just the 0s and 1s

P.S also, how can I make the empty space in the "1" column under Amblyopia show the number zero instead of a blank?

Upvotes: 0

Views: 159

Answers (1)

e.matt
e.matt

Reputation: 886

NESTFH2<-data.frame(FH=c(rep(1,20),rep(0,20)),
                        Diagnosis.=c(rep(1,12),rep(0,28)),
                        Strabismus.=c(rep(1,12),rep(0,28)),
                        Amblyopia.=c(rep(1,12),rep(0,28)),
                        Glasses.=c(rep(1,12),rep(0,28))) #created some data



    NESTFH2.withlabs <- apply_labels(NESTFH2,
                                     FH = "FH",
                                     FH = c("Yes" = 1, "No" = 0),
                                     Diagnosis.= "Diagnosis", # the group name
                                     Diagnosis. = c("Yes" = 1,"No" = 0), # the label within that group
                                     Strabismus.= "Strabismus",
                                     Strabismus.= c("Yes" = 1,"No" = 0),
                                     Amblyopia. = "Amblyopia",
                                     Amblyopia.= c("Yes" = 1,"No" = 0),
                                     Glasses. = "Glasses",
                                     Glasses.= c("Yes" = 1,"No" = 0)) #apply the label you want and store with a new name

    NESTFH2 %>% tab_cells(FH) %>% tab_cols(Diagnosis.,Strabismus.,Amblyopia.,Glasses.) %>% tab_stat_cases() %>% tab_pivot() # your orginal attempt
    NESTFH2.withlabs %>% tab_cells(FH) %>% tab_cols(Diagnosis.,Strabismus.,Amblyopia.,Glasses.) %>% tab_stat_cases() %>% tab_pivot() #your desired outcome 

    cro_cases(NESTFH2.withlabs$FH, list(total(),NESTFH2.withlabs$Diagnosis., NESTFH2.withlabs$Strabismus.,NESTFH2.withlabs$Amblyopia.,NESTFH2.withlabs$Glasses.)) #labelling above should now help with the send part of your question

Upvotes: 1

Related Questions