문제

Suppose I print a data frame called summary_table as follows:

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")

Now suppose summary_table has only three rows, but twelve columns. I'd like to flip (transpose) the table so that the columns become rows.

Any easy way?

도움이 되었습니까?

해결책

How about using the t() function:

print(xtable(t(summary_table),
         align=rep("r",4),
         caption="A summary of stuff."),
  table.placement="H")

Your example is not reproducible, so I cannot test it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top