Skip to contents

This function calculates the median intensity for each variable in the mass_dataset object based on the specified samples and adds it as a new column to the variable information.

Usage

mutate_median_intensity(object, according_to_samples = "all", na.rm = TRUE)

Arguments

object

A mass_dataset object.

according_to_samples

A character vector specifying the samples to consider for the median calculation. Default is "all".

na.rm

Logical, whether to remove NA values before calculating the median. Default is TRUE.

Value

A modified mass_dataset object with added median intensity information.

Author

Xiaotao Shen xiaotao.shen@outlook.com

Examples

data("expression_data")
data("sample_info")
data("variable_info")

object <- create_mass_dataset(
  expression_data = expression_data,
  sample_info = sample_info,
  variable_info = variable_info
)

object2 <- mutate_median_intensity(object = object, na.rm = TRUE)
head(extract_variable_info(object2))
#>                 variable_id        mz        rt median_intensity
#> M136T55_2_POS M136T55_2_POS 136.06140  54.97902        1676180.4
#> M79T35_POS       M79T35_POS  79.05394  35.36550        2777897.0
#> M307T548_POS   M307T548_POS 307.14035 547.56641         273687.8
#> M183T224_POS   M183T224_POS 183.06209 224.32777        5103244.9
#> M349T47_POS     M349T47_POS 349.01584  47.00262        7169041.1
#> M182T828_POS   M182T828_POS 181.99775 828.35712        4433034.2

qc_samples <- get_sample_id(object)[extract_sample_info(object)$class == "QC"]
object3 <- mutate_median_intensity(object = object2, according_to_samples = qc_samples)
head(extract_variable_info(object3))
#>                 variable_id        mz        rt median_intensity
#> M136T55_2_POS M136T55_2_POS 136.06140  54.97902        1676180.4
#> M79T35_POS       M79T35_POS  79.05394  35.36550        2777897.0
#> M307T548_POS   M307T548_POS 307.14035 547.56641         273687.8
#> M183T224_POS   M183T224_POS 183.06209 224.32777        5103244.9
#> M349T47_POS     M349T47_POS 349.01584  47.00262        7169041.1
#> M182T828_POS   M182T828_POS 181.99775 828.35712        4433034.2
#>               median_intensity.1
#> M136T55_2_POS          1447844.3
#> M79T35_POS             2063212.8
#> M307T548_POS            342037.7
#> M183T224_POS                  NA
#> M349T47_POS            6417851.6
#> M182T828_POS           3662819.1