如何在 R Markdown 中创建动态 table 标题

How to create dynamic table heading in R Markdown

我想创建一个动态 table 标题,它会根据回归系数 (k,a,b,c,d,..,n,n+1) 和回归系数的数量进行更新方程(U4ST,U4STAW,...n,n+1).

是否可以使用下面代码中提供的“Y”和“X”变量来使 table 动态,以便它可以在 X 和 Y 变量的长度减少或增加时发生变化?谢谢你。

txt = "Base Condition,k,a,b,c
U4ST,0.29,-3.12,0.27,0.16
U4STAW,1.24,-12.37,1.22,0.27
U3ST,3.18,-5.35,0.34,0.28
U4SG,0.38,-3.47,0.42,0.14
SHS U4SG,0.38,-3.47,0.42,0.14
SHS U4ST,0.29,-3.12,0.27,0.16"
txtTable=TextToTable(txt, sep=",", dimnames=c("Index","Safety Analyst SPF  Coefficients"), header=TRUE)


Y=length(txtTable[,1])
X=length(txtTable[2,])-1

#table
txtTable %>% kable(align= 'c', caption = "Information System X Regression Coefficients for Y Base Condition regression equations")```

当我正确理解问题时,解决方案应该只是`粘贴?功能:

txtTable %>% kable(align= 'c', caption = paste0("Information System ",X, " Regression Coefficients for ", Y," Base Condition regression equations"))