簡體   English   中英

在 R 中使用 kable 創建表

[英]Create table using kable in R

這是我使用的代碼(在 StackOverflow 社區的大力幫助下:)使用相同的數據創建更簡單的表:

library(here)

ANOVA_Relationship_Subset_sum <- ANOVA_Relationship_Subset %>%
  dplyr::group_by(treatment) %>%
  dplyr::summarize(
    n=n(),
    mean=mean(TotalComm), 
    `std. dev` = sd(TotalComm)
  )
ANOVA_Relationship_Subset_sum

現在我要處理一些更復雜的事情; 如何創建這樣的表: 在此處輸入圖像描述

如果有幫助,這是我的數據:

structure(list(study = c(4, 4, 4, 1, 1, 1), TREATMENT = c(0, 
0, 0, 0, 0, 0), TREATMENT4 = c(0, 0, 0, 0, 0, 0), TREATMENT2 = c(0, 
0, 0, 0, 0, 0), TREATMENT3 = c(0, 0, 0, 0, 0, 0), order = c(NA_real_, 
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), id = c(279, 
238, 239, 135, 143, 138), treatment = c(0, 0, 0, 0, 0, 0), treatment_condition = c(NA_real_, 
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), control_condition = c(NA_real_, 
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), m_check1 = c(1, 
1, 1, 1, 1, 1), relationship = c(NA, NA, NA, 7, 6, 5), payment = c(NA, 
NA, NA, 10, 3, 3), educ_level = c(14, 14, 12, 16, 16, 18), golf = c(3, 
5, 3, 3, 2, 3), male = c(1, 0, 1, 0, 0, 1), Asian = c(0, 1, 0, 
0, 0, 0), Black = c(0, 0, 0, 0, 0, 0), Latino = c(1, 0, 0, 0, 
0, 0), White = c(0, 0, 1, 1, 1, 1), age = c(27, 53, 49, 25, 28, 
24), English = c(1, 1, 1, 1, 1, 1), education = c(16, 16, 14, 
14, 14, 16), enjoy = c(4, 1, 3.5, 4.25, 3.25, 3.5), RELATIONSHIP = c(4.33333349227905, 
1, 4.33333349227905, 3.66666674613953, 3.5, 3.66666674613953), 
    anxiety = c(3, 3.40000009536743, 2.20000004768372, 1.25, 
    2, 1.25), BEH_SIM = c(3, 1, 3.75, 2.75, 2.5, 1.75), sptconf = c(3.33333325386047, 
    1.5, 4, 4.83333349227905, 4, 3.66666674613953), NEG_EFFICACY = c(4, 
    1.16666662693024, 3.66666674613953, 4.83333349227905, 4.16666650772095, 
    4.5), spteffort = c(3.16666674613953, 3.5, 4.16666650772095, 
    3.16666674613953, 3.16666674613953, 3.5), SPTEFFORT_OTHER = c(3.16666674613953, 
    3.5, 3.5, 3.16666674613953, 3, 3.33333325386047), SIM_VALUES = c(3.75, 
    1, 3.75, 3.75, 1.5, 2.25), COOP_MOTIV = c(2.33333325386047, 
    3, 2.66666674613953, 5, 2.5, 2.66666674613953), COMP_MOTIV = c(5, 
    5, 3.20000004768372, 4.40000009536743, 2.40000009536743, 
    4.40000009536743), presence = c(NA, NA, NA, 2.79999995231628, 
    1.79999995231628, 2.59999990463257), environ = c(NA, NA, 
    NA, 3, 4, 3), openresponse = c(NA, NA, NA, 94.25, 86, 60), 
    TotalOwnerCommission = c(300, 266.666656494141, 258.333343505859, 
    266.666656494141, 383.333343505859, 325), TotalRangerComm = c(258.333343505859, 
    233.33332824707, 291.666656494141, 258.333343505859, 175, 
    166.66667175293), TotalComm = c(279.166687011719, 250, 275, 
    262.5, 279.166687011719, 245.833343505859), merge = c(1, 
    1, 1, 0, 0, 0), Control = c(1, 1, 1, NA, NA, NA), treatment_Shoes = c(0, 
    0, 0, NA, NA, NA), treatment_Instructions_Only = c(0, 0, 
    0, NA, NA, NA), treatment_Info_Only = c(0, 0, 0, NA, NA, 
    NA), treatment_Info_Instructions = c(0, 0, 0, NA, NA, NA), 
    group = c("OwnerOnly", "OwnerOnly", "OwnerOnly", "", "", 
    ""), race = c(4, 2, 5, NA, NA, NA), race_a = c("", "", "", 
    "", "", ""), RELATIONSHIP_2 = c(9.02055358886719, 1, 9.02055358886719, 
    7.02113246917725, 6.54790019989014, 7.02113246917725), TotalOwnerCommission_2 = c(5196.15234375, 
    4354.64794921875, 4152.12744140625, 4354.64794921875, 7505.24560546875, 
    5859.02099609375)), row.names = c(NA, -6L), class = c("tbl_df", 
"tbl", "data.frame"))

簡而言之,我要感謝 SO 社區對 R 的所有幫助。 如果沒有你們的幫助,我不知道我怎么會走到這一步。

嘗試apaTables Package,按照示例格式化數據,並使用apa.aov.table() function 將表格轉換為 APA 樣式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM