【发布时间】:2021-08-14 14:46:43
【问题描述】:
以下是我正在处理的数据示例:
> dput(candidateEvokeDFYoung)
structure(list(youngTreatment = structure(c(NA, 1, 0, 1, 0, 1,
0, 1, 1, 0, 1, 1, 0, 0, NA, NA, NA, NA, 1, 1), format.stata = "%10.0g"),
candTrustworthy = structure(c(0, 0, 0, 0, 0, 0, 0, 1, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), format.stata = "%10.0g"),
candKnowledgeable = structure(c(1, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1), format.stata = "%10.0g"),
candQualified = structure(c(0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1), format.stata = "%10.0g"),
candConservative = structure(c(0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0), format.stata = "%10.0g"),
candLiberal = structure(c(0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0), format.stata = "%10.0g"), candInexperienced = structure(c(0,
1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0), format.stata = "%10.0g"),
candPrincipled = structure(c(1, 1, 0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 1, 1, 1, 0, 0, 0, 0), format.stata = "%10.0g"),
candDistance = structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 0, 0), format.stata = "%10.0g"),
candEfficacy = structure(c(1, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 1, 0, 0), format.stata = "%10.0g")), row.names = c(NA,
-20L), class = c("tbl_df", "tbl", "data.frame"))
我想要做的是使用带有 t.test 结果的表包生成一个表。我遇到的麻烦是我已经获取了这个数据集并使用 lapply 计算了我对每个变量的 t.tests,其中 youngTreatment 作为我的“y”变量:
candidateEvokesDiffYoung = lapply(candidateEvokeDFYoung[-1], function(x) t.test(x ~ candidateEvokeDFYoung$youngTreatment))
这给了我一个列表列表。我不知道如何使用 tables::tabular 访问
list[['statistic']]
和
list[['p.value]]
我当然可以自己手动将所有这些都拉出来,并将其放入 stargazer 或其他东西的数据框中,但我想知道是否有人知道我可以如何更有效地使用表格包来做到这一点。
【问题讨论】: