0

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

我尝试过使用两种不同的方法来制作表格,但都给了我同样的问题。

第一个至少给了我标题中的变量名:

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

带有标题的表 - 但子标题是 0 和 1

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

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

表甚至没有任何标题,只有 0 和 1

PS 另外,如何使弱视下“1”列中的空白区域显示数字零而不是空白?

4

1 回答 1

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
于 2019-07-18T08:27:31.057 回答