replace_missing_values: Replace missing values in a CF-MS chromatogram matrix

Description Usage Arguments Value Examples

View source: R/replace_missing_values.R

Description

Sanitize different representations of missing values (e.g., zeroes, NaNs, or infinite values) in a chromatogram matrix, then optionally replace them all with zeroes or with near-zero noise.

Usage

1
2
3
4
5
replace_missing_values(
  mat,
  missing = c("NA", "zero", "noise"),
  noise_floor = 0.001
)

Arguments

mat

a CF-MS chromatogram matrix, with proteins in rows and fractions in columns

missing

one of 'NA', 'zero', or 'noise'. If 'zero', missing values will be replaced with zeroes. If 'noise', missing values will be replaced with random noise, sampled from a uniform distribution with a maximum value of noise_floor. If 'NA', missing values will be left as NAs.

noise_floor

upper limit of the uniform distribution for missing = 'noise'

Value

a copy of the input matrix with missing values optionally replaced

Examples

1
2
3
4
5
6
7
8
mat = matrix(rnorm(100), ncol = 10, nrow = 10,
             dimnames = list(paste0('protein_', LETTERS[1:10]),
                             paste0('fraction_', seq_len(10))))
mat[sample(seq_along(mat), 5)] = 0
mat[sample(seq_along(mat), 8)] = NA
mat[sample(seq_along(mat), 2)] = Inf
sanitized = replace_missing_values(mat, missing = 'zero')
table(sanitized == 0)

fosterlab/CFTK documentation built on Jan. 19, 2021, 10:31 p.m.