Learn R Programming

ASRgenomics (version 1.1.4)

full2sparse: 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)

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.

Arguments

K

A square matrix in full form (\(n \times n\)) (default = NULL).

drop.zero

If TRUE observations equal to zero are dropped (default = TRUE).

Details

Based on the function published by Borgognone et al. (2016).

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

Run this code
# 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"))

Run the code above in your browser using DataLab