As a short example, when running combn(1:5,2)
, I get a matrix of 2 rows and 10 columns.
I know I can convert the output matrix to a data frame, but is it possible (any option inside combn
) to have the output readily in the form of a vertical data frame of 2 columns and 10 rows ?
Thanks.
Asked
Active
Viewed 321 times
0
-
1Probably simplest is `data.frame(t(combn(1:5,2)))`. – lmo Feb 22 '17 at 13:43
1 Answers
2
Simply transpose the matrix with t()
:
data.frame(t(combn(1:5, 2)))
Yields:
X1 X2
1 1 2
2 1 3
3 1 4
4 1 5
5 2 3
6 2 4
7 2 5
8 3 4
9 3 5
10 4 5

setempler
- 1,681
- 12
- 20
-
OK, thanks ! I will do this, as it seems that no options is available in combn(*:*,*) to give directly a vertical dataframe output... – Andrew Feb 23 '17 at 09:33