Scope (27)
Query functions (4)
These functions can be used to retrieve the names of rows, columns, and dimensions:
(They correspond to S's and R's functions rownames, colnames, dimnames.)
Underlying sparse array:
Dimensions:
Array rules:
Set row names (3)
Here is a copy of the sparse matrix:
Here we set different row names:
Matrix form of the result:
Set column names (2)
Here we set different column names:
Matrix form of the result:
Transpose (1)
Here we transpose and show the matrix form:
Sums (5)
Here is the sum of all elements:
Here are the row sums:
Here are the column sums:
Here are the row sums as Association:
Here are the column sums as Association:
Dot products
In order to make the SSparseMatrix objects really useful we have to implement matrix-vector and matrix-matrix operations for them. (With other SSparseMatrix objects and with SparseArray objects.)
This function is used to visualize the commands, the results, and the results’ heads.
Matrix by vector multiplication
Matrix by matrix multiplication (5)
Here is a sparse matrix (2D sparse array):
First we look into a dot product to the right of SSparseMatrix with a sparse array and a dot product to the left of SSparseMatrix with a sparse array:
This creates another SSparseMatrx object with no row and column names:
Next we look into two dot products of two SSparseMatrx objects:
Verification using SparseArray objects:
Part (4)
A major useful feature is to have Part work with row and column names. The implementation of that additional functionality for Part is demonstrated below.
In the cases when the dimension drops sparse arrays or numbers are returned. In R the operation "[" has the parameter "drop" -- the expression "smat[1,,drop=F]" is going to be a sparse matrix, the expression "smat[1,,drop=T]" is going to be a dense vector. The corresponding implementation is to have the option Drop→(True|False) for Part, but that does not seem a good idea.
In the tables with examples below the last rows show the heads of the results.
Single row or column retrieval:
Permutation of both row names and column names:
Various subsets:
More examples of various subsets:
Column-binding and row-binding (3)
Row- and column binding are useful in various data analysis scenarios.
When using column and row names there are couple of questions to be answered.
1. How duplication of column (row) names is handled?
2. How can we specify to ignore the column (row) names in the binding process?
Here are three matrices:
Here are column binding results:
Here are row binding results: