【发布时间】:2021-03-11 03:16:13
【问题描述】:
现在我所拥有的类似于以下内容。我不知道如何在 R 中自动生成 Latex 代码来创建一个像上面那样的表。
我正在使用以下 R 代码来生成表格。然后我将代码复制并粘贴到 Latex 中,使其出现在 pdf 中。
#Build a rough summary table
summary1 <-
list("Age (Years)" =
list("Missing" = ~ sum(is.na(df$age_years)),
"Type" = ~ if(is.numeric(df$age_years)==TRUE) {print("Numeric")} else {print("Character")},
"Min" = ~ min(age_years),
"Max" = ~ max(age_years),
"Mean" = ~ format(round(mean(df$age_years), 2), nsmall = 2),
"SD" = ~ format(round(sd(df$age_years), 2), nsmall = 2)),
"Female" =
list("Missing" = ~ sum(is.na(df$sex_DV)),
"Type" = ~ if(is.numeric(df$sex_DV)==TRUE) {print("Numeric")} else {print("Character")},
"Min" = ~ min(sex_DV),
"Max" = ~ max(sex_DV),
"Mean" = ~ format(round(mean(df$sex_DV), 2), nsmall = 2),
"SD" = ~ format(round(sd(df$sex_DV), 2), nsmall = 2))
)
whole <- summary_table(df,summary1)
whole
欢迎任何帮助。谢谢!
编辑:具有可重现部分的数据(不是实际数据)
> df
age_years sex
1 33 0
2 11 1
3 45 1
4 67 0
5 8 0
6 99 0
【问题讨论】:
-
您能否提供一个基础数据样本?你可以
dput(df)输出这个 -
@EmilyKothe 我放了一个简短版本的 df,只有两个变量。这就是我想在摘要中显示表格的方式
-
标签列的信息存储在哪里? (即它们是否存储为这些变量的属性?)
-
@EmilyKothe 哦,那来自另一个数据集。这更像是一个例子。我现在正在尝试遵循该结构。我的数据集中没有标签列,因此可以避免该部分。我想基本遵循
wide dataset格式