0

I have an R data table where one of the columns is effectively a factor, say, day of the week. How can I arrange a different column of the table into a matrix, and that matrix's columns correspond to each day of the week?

For example, the original table is

Mon  21   A
Tue  50   C
Thur 12   D
Wed  11   K
...
Mon  9    B
Wed  100  S
Tue  99   Z
Thur 32   J

where it is guaranteed each day of the week (in this sample only Mon - Thur) appear the same number of times. Now I want to arrange the 2nd column to a matrix of (with the column title in parenthesis, not part of the matrix)

(Mon Tue Wed Thur)

21  50  11  12
...
9   99  100 32

What is the best way to do that? Thx!

Zhang18
  • 4,800
  • 10
  • 50
  • 67

1 Answers1

0

Try using a auxiliar array to save the current one then you get the first column and display into a line on the new array. Do it do the second column and display into a line, and go on....