![]() |
VOOZH | about |
The as.matrix() function within R converts objects of various classes into a matrix. This can be helpful to work with structures of various data that can be converted into the matrix structure so that it becomes easier to analyze.
as.matrix(x)
Parameters:
[,1] [1,] 1 [2,] 2 [3,] 3 [4,] 4 [5,] 5 [6,] 6 [7,] 7 [8,] 8 [9,] 9
Example 2: Convert a Data Frame to a Matrix
Time demand 1 1 8.3 2 2 10.3 3 3 19.0 4 4 16.0 5 5 15.6 6 7 19.8 Time demand [1,] 1 8.3 [2,] 2 10.3 [3,] 3 19.0 [4,] 4 16.0 [5,] 5 15.6 ...
Output
3 x 3 sparse Matrix of class "dtCMatrix"
[1,] . . 1
[2,] . . 2
[3,] . . .
[,1] [,2] [,3]
[1,] 0 0 1
[2,] 0 0 2
[3,] 0 0 0
Output
coordinates ID
1 (1, 4) 1
2 (2, 5) 2
3 (3, 6) 3
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6