Skip to contents

This function adds a new column to the variable_info slot of a mass_dataset object, which contains the relative standard deviation (RSD) for each variable according to the samples specified.

Usage

mutate_rsd(object, according_to_samples = "all")

Arguments

object

A mass_dataset object.

according_to_samples

A character vector specifying the sample IDs to consider when calculating the RSD. Default is "all", which considers all samples.

Value

A modified mass_dataset object with an updated variable_info slot.

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_rsd(object = object)
head(extract_variable_info(object2))
#>                 variable_id        mz        rt       rsd
#> M136T55_2_POS M136T55_2_POS 136.06140  54.97902 50.756560
#> M79T35_POS       M79T35_POS  79.05394  35.36550 28.257007
#> M307T548_POS   M307T548_POS 307.14035 547.56641 35.041286
#> M183T224_POS   M183T224_POS 183.06209 224.32777  1.224228
#> M349T47_POS     M349T47_POS 349.01584  47.00262 27.715030
#> M182T828_POS   M182T828_POS 181.99775 828.35712 25.534063

qc_samples <- get_sample_id(object)[extract_sample_info(object)$class == "QC"]
object3 <- mutate_rsd(object = object2, according_to_samples = qc_samples)
head(extract_variable_info(object3))
#>                 variable_id        mz        rt       rsd    rsd.1
#> M136T55_2_POS M136T55_2_POS 136.06140  54.97902 50.756560 40.05551
#> M79T35_POS       M79T35_POS  79.05394  35.36550 28.257007 51.97966
#> M307T548_POS   M307T548_POS 307.14035 547.56641 35.041286 28.26044
#> M183T224_POS   M183T224_POS 183.06209 224.32777  1.224228       NA
#> M349T47_POS     M349T47_POS 349.01584  47.00262 27.715030 50.95194
#> M182T828_POS   M182T828_POS 181.99775 828.35712 25.534063       NA