سؤال

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