如何修复标题以显示标签而不是零和一?

时间:2019-07-17 22:28:53

标签: r expss

在R-studio中使用expss包制作表格,但与expss示例不同,标头不显示其标签和区域,而是显示零和一。

我尝试使用两种不同的方式制作表格,但都给我一个相同的问题。

第一个至少为我提供了标题中的变量名称:

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

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

第二个甚至没有在标题中给出变量名:

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

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

P.S同样,如何使弱视的“ 1”栏中的空白显示数字零而不是空白?

1 个答案:

答案 0 :(得分:1)

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