ps_mutate: Modify or compute new sample_data in phyloseq object

View source: R/ps_mutate.R

ps_mutateR Documentation

Modify or compute new sample_data in phyloseq object

Description

Add or compute new phyloseq sample_data variables. Uses dplyr::mutate() syntax.

Usage

ps_mutate(ps, ...)

Arguments

ps

phyloseq object with sample data

...

passed straight to dplyr::mutate (see examples and dplyr::mutate help)

Value

phyloseq object with modified sample_data

See Also

tax_mutate for manipulation of tax_table variables

mutate

Examples

library(phyloseq)
library(dplyr)
data("enterotype")

sample_data(enterotype)[1:10, ]

months_in_year <- 12
ps <- enterotype %>%
  ps_mutate(
    age_months = Age * months_in_year,
    IDs_match = as.character(Sample_ID) == as.character(SampleID),
    placeholder = "Word"
  )

sample_data(ps)[1:10, ]

# Using the dplyr::across functionality is also possible
ps <- ps %>%
  ps_mutate(
    dplyr::across(where(is.factor), toupper),
    another_var = TRUE,
    SeqTech = NULL # deletes SeqTech variable
  )

head(sample_data(ps))

david-barnett/microViz documentation built on April 17, 2025, 4:25 a.m.