as.df: Shortcut for 'as.data.frame()' allowing to name the columns...

View source: R/shortenFuns.R

as.dfR Documentation

Shortcut for as.data.frame() allowing to name the columns as well

Description

Shortcut for as.data.frame() allowing to name the columns as well

Usage

as.df(..., col.names = NULL)

Arguments

...

same arguments as for as.data.frame()

col.names

character vector for the names of the data.frame (colnames)

Examples

(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

salix-d/salixUtils documentation built on Aug. 14, 2024, 7:11 a.m.