在R-studio中使用expss包制作表格,但与expss示例不同,标头不显示其标签和区域,而是显示零和一。
我尝试使用两种不同的方式制作表格,但都给我一个相同的问题。
第一个至少为我提供了标题中的变量名称:
NESTFH2 %>% tab_cells(FH) %>% tab_cols(Diagnosis.,Strabismus.,Amblyopia.,Glasses) %>% tab_stat_cases() %>% tab_pivot()
第二个甚至没有在标题中给出变量名:
cro_cases(FH, list(Diagnosis.,Strabismus., Amblyopia., Glasses="Glasses"))
P.S同样,如何使弱视的“ 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