full2sparse {ASRgenomics} | R Documentation |
Generates a sparse form matrix from a full form matrix
Description
Modifies the input square matrix into its sparse form with three columns per line,
corresponding to the set: Row, Col, Value
. This matrix defines the lower triangle
row-wise of the original matrix and it is sorted as columns within row.
Values of zero on the matrix are dropped by default. Individual
names should be assigned to rownames
and colnames
.
Usage
full2sparse(K = NULL, drop.zero = TRUE)
Arguments
K |
A square matrix in full form ( |
drop.zero |
If |
Details
Based on the function published by Borgognone et al. (2016).
Value
A matrix in sparse form with columns: Row, Col, Value
together with the attributes rowNames
and colNames
.
If attribute INVERSE
is found this is also passed to the sparse matrix.
References
Borgognone, M.G., Butler, D.G., Ogbonnaya, F.C and Dreccer, M.F. 2016. Molecular marker information in the analysis of multi-environment trial helps differentiate superior genotypes from promising parents. Crop Science 56:2612-2628.
Examples
# Get G matrix.
G <- G.matrix(M = geno.apple, method = "VanRaden", sparseform = FALSE)$G
G[1:5, 1:5]
# Transform matrix into sparse.
G.sparse <- full2sparse(K = G)
head(G.sparse)
head(attr(G.sparse, "rowNames"))
head(attr(G.sparse, "colNames"))