I have a large data set and i want to convert it into array. But for instance lets have a simple example.
I have following matrix
`\begin{table}[ht]
\begin{center}
\begin{tabular}{rrrrrrr}
\hline
& 1 & 2 & 3 & 4 & 5 & 6 \\
\hline
1 & 1 & 11 & 21 & 31 & 41 & 51 \\
2 & 2 & 12 & 22 & 32 & 42 & 52 \\
3 & 3 & 13 & 23 & 33 & 43 & 53 \\
4 & 4 & 14 & 24 & 34 & 44 & 54 \\
5 & 5 & 15 & 25 & 35 & 45 & 55 \\
6 & 6 & 16 & 26 & 36 & 46 & 56 \\
7 & 7 & 17 & 27 & 37 & 47 & 57 \\
8 & 8 & 18 & 28 & 38 & 48 & 58 \\
9 & 9 & 19 & 29 & 39 & 49 & 59 \\
10 & 10 & 20 & 30 & 40 & 50 & 60 \\
\hline
\end{tabular}
\end{center}
\end{table}
`
What i need is to convert this matrix into array of dimension (5,6,2), in which first matrix contains first five rows of “x” and second matrix will contain last 5 rows.
I have tried
dim(x)<-c(5,6,2)
which makes the matrix-1 with 1:30 consecutive numbers and then matrix-2 with 31:60 consecutive numbers. Which is not my requirement.
Thanks in advance.
What you offered is a LaTeX representation. The same matrix in R would be
Consider using
abindfrom package “abind”:If you didn’t want to use an outside package and would settle for the transposed version of each slice, then transpose first and then re-dimension. You cannot transpose an array, however, there is an
apermfunction you could look at:The aperm solution: