![](/img/trans.png)
[英]Descriptive tables - how to create a table containing both numeric and categorical variables
[英]Compare two variables (both numeric or both factors) in expss tables
I am digging deeper and deeper into the expss package, and face one of the examples mentioned here --> https://gdemin.github.io/expss/#example_of_data_processing_with_multiple-response_variables (more particularly the last table of the section.
考慮以下數據框:
vecA <- factor(c(rep(1,10),rep(2,10),rep(3,10),rep(4,10),rep(5,10)),levels=c(1,2,3,4,5))
vecB <- factor(c(rep(1,20),rep(2,20),rep(NA,10)),levels=c(1,2,3,4,5))
df_fact <- data.frame(vecA, vecB)
vecA_num <- as.numeric(c(rep(1,10),rep(2,10),rep(3,10),rep(4,10),rep(5,10)))
vecB_num <- as.numeric(c(rep(1,20),rep(2,20),rep(NA,10)))
df_num <- data.frame(vecA, vecB)
嚴格復制建議的代碼(上面的 URL),這是我的表格的樣子:
df_fact %>%
tab_cols(total(label = "#Total| |")) %>%
tab_cells(list(vecA)) %>%
tab_stat_cpct(label="vecA", total_row_position="above", total_statistic="u_cases") %>%
tab_cells(list(vecB)) %>%
tab_stat_cpct(label="vecB", total_row_position="above", total_statistic="u_cases") %>%
tab_pivot(stat_position = "inside_columns") %>%
recode(as.criterion(is.numeric) & is.na ~ 0, TRUE ~ copy)
與數字示例略有不同的過程:
df_num %>%
tab_cols(total(label = "#Total| |")) %>%
tab_cells(vecA_num, vecB_num) %>%
tab_stat_valid_n(label = "Valid N") %>%
tab_stat_mean(label="Mean") %>%
tab_pivot(stat_position = "inside_columns") %>%
recode(as.criterion(is.numeric) & is.na ~ 0, TRUE ~ copy) %>%
tab_transpose()
問題從這里開始,因為這些復雜的結構是……復雜的!
1)我想包括 tab_last_sig* 系列函數,但我不知道如何去做(當變量是因素時,可能還有小計/網)
2) 包括多個統計數據(案例、百分比、平均值……)是一個挑戰
3)最后,我不清楚我應該在哪里寫統計名稱/變量名稱
我還沒有找到這些構造的詳細文檔,因此這個消息在一個瓶子里:)
tab_stat_
。 但復雜的表格布局確實是一個挑戰:(tab_cells
中。 之后,您可以使用tab_stat_mean
、 tab_stat_cpct
等編寫統計函數。您可以通過在 R 控制台中打印?tab_pivot
來查找文檔。 這是獲取 R 功能手冊的標准方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.