View source: R/intervals-to-mat.R
| gintervals.to_mat | R Documentation |
Builds a numeric matrix of value columns whose rows are indexed by
intervals. The intervals are carried in attr(mat, "intervals") as the
authoritative identity; rownames(mat) are display-only (default
"chrom:start-end") and are NEVER parsed back by
gintervals.from_mat. This avoids the round-trip corruption
that occurs when chrom names contain underscores or other separators.
gintervals.to_mat(df, id_col = NULL, value_cols = NULL, labels = TRUE)
df |
data.frame with |
id_col |
optional column name in |
value_cols |
character vector of column names to use as matrix data.
If |
labels |
if |
An intervs_mat object: a numeric matrix subclass with the
intervals attached as attr(., "intervals"). Supports row/column
subsetting ([) and rbind() while preserving the attribute.
gintervals.from_mat
df <- data.frame(
chrom = c("chr1", "chr1", "chr2"),
start = c(100L, 500L, 200L),
end = c(200L, 700L, 400L),
t1 = c(1.5, 2.5, 3.5),
t2 = c(10, 20, 30)
)
mat <- gintervals.to_mat(df)
rownames(mat)
# subset preserves intervals:
sub <- mat[c(1, 3), ]
attr(sub, "intervals")
# round-trip back to a data.frame:
gintervals.from_mat(sub)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.