Building MicrobiomeStat from Matrix and Data.frame
Discover how to craft the MicrobiomeStat data object using matrices and data frames from your R environment or by importing data from external CSV files.
1. Using Existing Data in R Environment
Starting from matrix and data.frame
# Step 1: Create the sample names.
# We want 20 sample names, each prefixed with "S". We use the `paste0` function to concatenate "S" with the numbers 1 through 20.
samplenames <- paste0("S",1:20)
# Step 2: Create the feature names.
# We want 100 feature names, each prefixed with "OTU". We use the `paste0` function to concatenate "OTU" with the numbers 1 through 100.
featurenames <- paste0("OTU",1:100)
# Step 3: Create the Feature.tab matrix.
# We want a matrix with 100 rows and 20 columns, filled with random counts.
# We then set the row and column names of this matrix to the feature and sample names we created earlier.
Feature.tab <- matrix(sample(1:1000, 100*20, repl = TRUE),nrow=100,ncol=20)
rownames(Feature.tab) <- featurenames
colnames(Feature.tab) <- samplenames
# Step 4: Create the Meta.dat data frame.
# We want a data frame with two columns: "group" and "weight".
# The "group" column should have 10 "case"s followed by 10 "control"s.
# The "weight" column should have 20 random numbers from a normal distribution with mean 70 and standard deviation 5.
# We then set the row names of this data frame to the sample names we created earlier.
# Create the Meta.dat dataframe
Meta.dat <- data.frame(
group = rep(c("control","case"), each=10),
weight = rnorm(20,70,5)
)
# Convert the "group" column to a factor and set "control" as the reference level
Meta.dat$group <- relevel(as.factor(Meta.dat$group), ref="control")
rownames(Meta.dat) <- samplenamesAdd Feature Annotation
Add Phylogenetic Tree (Optional)
Combine into MicrobiomeStat Object

MicrobiomeStat data object using R's str function. Additionally, the successful validation of the object with mStat_validate_data(MicrobiomeData) confirms its readiness for subsequent analyses.2. Using External CSV Data
Download Sample Data Files
Import Data from CSV
Combine into MicrobiomeStat Object

MicrobiomeStat data object using R's str function, illustrating the organization of the components sourced from external CSV files.Add Phylogenetic Tree
PreviousCreating the MicrobiomeStat Data ObjectNextConverting Data from Phyloseq into MicrobiomeStat
Last updated