![](/img/trans.png)
[英]How to change colors and attributes of Table of Contents in R Markdown HTML document?
[英]How to transpose a table in an R markdown document?
假設我如下打印一個名為summary_table的數據框:
summary_table = data.frame(a=c(1,2,3), b=c(11,12,13),c=c(21,22,23),d=c(31,32,33),e=c(41,42,43),f=c(51,52,53),g=c(61,62,63),h=c(71,72,73),i=c(81,82,83),j=c(91,92,93),k=c(101,102,103),l=c(111,112,113))
print(xtable(summary_table,
align=rep("r",13),
caption="A summary of stuff."),
table.placement="H")
現在,假設summary_table只有三行,但只有十二列。 我想翻轉(轉置)表格,使列成為行。
有什么簡單的方法嗎?
如何使用t()
函數:
print(xtable(t(summary_table),
align=rep("r",4),
caption="A summary of stuff."),
table.placement="H")
您的示例不可復制,因此我無法對其進行測試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.