3

I wanting to arrange the tab_cols from the expss package.

for example i want to order cols d,b,c from my test data set (below). Its seems cols are tabbed alphabetically..

test<-data.frame(group=c(rep("b",3),rep("c",3),rep("d",3)),num=1:9)

 test
  group num
1     b   1
2     b   2
3     b   3
4     c   4
5     c   5
6     c   6
7     d   7
8     d   8
9     d   9

This code

test %>%
  tab_cells(num) %>%
  tab_cols(group) %>%
  tab_stat_mean() %>%
  tab_pivot()

yields

 |     |      | group |    |    |
 |     |      |     b |  c |  d |
 | --- | ---- | ----- | -- | -- |
 | num | Mean |     2 |  5 |  8 |

desired output is

 |     |      | group |    |    |
 |     |      |     d |  b |  c |
 | --- | ---- | ----- | -- | -- |
 | num | Mean |     8 |  2 |  5 |
zx8754
  • 52,746
  • 12
  • 114
  • 209
e.matt
  • 836
  • 1
  • 5
  • 12

0 Answers0