as.df | R Documentation |
as.data.frame()
allowing to name the columns as wellShortcut for as.data.frame()
allowing to name the columns as well
as.df(..., col.names = NULL)
... |
same arguments as for |
col.names |
character vector for the names of the data.frame (colnames) |
(mat <- matrix(
data = c("Plantae", "Plantae", "Plantae",
"Tracheophyta", "Tracheophyta", "Tracheophyta",
"Magnoliopsida", "Magnoliopsida", "Pinopsida",
"Sapindales", "Magnoliales", "Pinales",
"Sapindaceae", "Magnoliaceae", "Pinaceae",
"Acer", "NA", "Pinus",
"Acer saccharum", "NA", "NA"),
nrow = 3,
dimnames = list(NULL, c("rank1", "rank2", "rank3", "rank4", "rank5", "rank6", "rank7"))))
# given this taxonomy matrix
# rank1 rank2 rank3 rank4 rank5 rank6 rank7
# [1,] "Plantae" "Tracheophyta" "Magnoliopsida" "Sapindales" "Sapindaceae" "Acer" "Acer saccharum"
# [2,] "Plantae" "Tracheophyta" "Magnoliopsida" "Magnoliales" "Magnoliaceae" "NA" "NA"
# [3,] "Plantae" "Tracheophyta" "Pinopsida" "Pinales" "Pinaceae" "Pinus" "NA"
# we want to convert into a data.frame
# and rename rows to their corresponding to ASV[i] and columns to their corresponding rank
tax <- as.df(mat,
row.names = paste0("ASV", seq_len(nrow(mat))),
col.names = c("kingdom", "phylum", "class", "order", "family", "genus", "species"))
tax
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.