使表中的重要效果在最终的pfd文档中以粗体显示

问题描述

我正在RMarkdown中工作,并且试图在Anova表中获得显着效果在最终的pdf文档中以粗体显示在这种情况下,需要加粗的行是表的第二行(列名是第一行)。

使用 papaja 软件包:link to GitHub

这就是我进行方差分析的方式

library(apaTables)
library(MOTE)
data("iris")
ManCheck2.1 <- aov(formula = Sepal.Length ~ Sepal.Width * Petal.Length,data = iris) 
ManCheck2.1APA <- apa_print(ManCheck2.1)

这是我准备详细表的步骤

M2 <- apa.aov.table(ManCheck2.1,conf.level = .95)
M2table <- M2$table_body
# Delete the "(Intercept)" line:
M2table <- M2table[-1,]
# Swap the p-values  with the formatted version from our apa_print() object IMPORTANT
M2table[2,6] <- as.character(ManCheck2.1APA$table$p[2])
M2table[1,6] <- as.character(ManCheck2.1APA$table$p[1])
M2table[3,6] <- as.character(ManCheck2.1APA$table$p[3])
# Rename the rows
M2table[,1] <- c("Company Motive","CSR","Company Motive * CSR","Error")
colnames(M2table) <- c("Predictor","$SS$","$df$","$MS$","$F$","$p$","$\\eta^{2}_{partial}$","$\\eta^{2}_{partial}$ 95\\% CI")

这是在我的针织文档中显示表格的代码块。

apa_table(M2table,caption = "Effects of self- (versus other-oriented motive) and high CSR (versus neutral CSR) on perceived company motive",note = "Significant effects are bold",align = c("l","r","c"),escape = F,row.names = F,# after manipulating the data frame,apa_table() started to show # the row numbers,so we had to choose "rownames = F" placement= "h")

解决方法

如果您只想使用预测变量名称,那么就足够了:

M2table <- M2$table_body

M2table[,1] <- c("","Company Motive","CSR","Company Motive * CSR","Error")
cond <- M2table$p != "" & as.numeric(M2table$p)<.01 
M2table[cond,1] <- paste0("\\textbf{",M2table[cond,1],"}")
M2table <- M2table[-1,]
# Rename the rows
# Swap the p-values  with the formatted version from our apa_print() object IMPORTANT
m2table[1:3,6] <- ManCheck2.1APA$table$p

colnames(M2table) <- c("Predictor","$SS$","$df$","$MS$","$F$","$p$","$\\eta^{2}_{partial}$","$\\eta^{2}_{partial}$ 95\\% CI")