Extends dplyr::mutate() to add or modify columns in a qseaSet's
sampleTable.
# S3 method for class 'qseaSet'
mutate(.data, ...)qseaSet
A qseaSet object whose sampleTable will be mutated.
Column transformations passed to dplyr::mutate(). For example,
over70 = age > 70, group = paste(tissue, tumour, sep = "_").
Default: none.
A qseaSet object with its sampleTable updated:
new columns are added,
existing columns are modified,
sample_name remains unchanged.
The order of samples is preserved.
The sample_name column cannot be changed with this function; use
renameQsetNames() or renameSamples() if sample names must be updated.
qsea::getSampleTable() to inspect metadata,
renameSamples() and renameQsetNames() for renaming,
filter.qseaSet() and selectQset() for other dplyr verbs.
data(exampleTumourNormal, package = "mesa")
# Add a new logical column based on age
exampleTumourNormal %>%
mutate(over70 = age > 70) %>%
qsea::getSampleTable()
#> sample_name group patient type tumour tissue age gender
#> Colon1_N Colon1_N Colon1_N Colon1 NormalColon Normal Colon 80 F
#> Colon1_T Colon1_T Colon1_T Colon1 CRC Tumour Colon 80 F
#> Colon2_N Colon2_N Colon2_N Colon2 NormalColon Normal Colon 67 F
#> Colon2_T Colon2_T Colon2_T Colon2 CRC Tumour Colon 67 F
#> Lung1_N Lung1_N Lung1_N Lung1 NormalLung Normal Lung 64 F
#> Lung1_T Lung1_T Lung1_T Lung1 LUAD Tumour Lung 64 F
#> Lung2_N Lung2_N Lung2_N Lung2 NormalLung Normal Lung 71 F
#> Lung2_T Lung2_T Lung2_T Lung2 LUSC Tumour Lung 71 F
#> Lung3_N Lung3_N Lung3_N Lung3 NormalLung Normal Lung 72 M
#> Lung3_T Lung3_T Lung3_T Lung3 LUAD Tumour Lung 72 M
#> stage over70
#> Colon1_N <NA> TRUE
#> Colon1_T III TRUE
#> Colon2_N <NA> FALSE
#> Colon2_T IV FALSE
#> Lung1_N <NA> FALSE
#> Lung1_T IIA FALSE
#> Lung2_N <NA> TRUE
#> Lung2_T IA TRUE
#> Lung3_N <NA> TRUE
#> Lung3_T IB TRUE
# Recode gender (better practice: use dplyr::case_when() or
# stringr::str_replace())
exampleTumourNormal %>%
mutate(gender = ifelse(gender == "F", "Female", "Male")) %>%
qsea::getSampleTable()
#> sample_name group patient type tumour tissue age gender
#> Colon1_N Colon1_N Colon1_N Colon1 NormalColon Normal Colon 80 Female
#> Colon1_T Colon1_T Colon1_T Colon1 CRC Tumour Colon 80 Female
#> Colon2_N Colon2_N Colon2_N Colon2 NormalColon Normal Colon 67 Female
#> Colon2_T Colon2_T Colon2_T Colon2 CRC Tumour Colon 67 Female
#> Lung1_N Lung1_N Lung1_N Lung1 NormalLung Normal Lung 64 Female
#> Lung1_T Lung1_T Lung1_T Lung1 LUAD Tumour Lung 64 Female
#> Lung2_N Lung2_N Lung2_N Lung2 NormalLung Normal Lung 71 Female
#> Lung2_T Lung2_T Lung2_T Lung2 LUSC Tumour Lung 71 Female
#> Lung3_N Lung3_N Lung3_N Lung3 NormalLung Normal Lung 72 Male
#> Lung3_T Lung3_T Lung3_T Lung3 LUAD Tumour Lung 72 Male
#> stage
#> Colon1_N <NA>
#> Colon1_T III
#> Colon2_N <NA>
#> Colon2_T IV
#> Lung1_N <NA>
#> Lung1_T IIA
#> Lung2_N <NA>
#> Lung2_T IA
#> Lung3_N <NA>
#> Lung3_T IB
# Change group by removing digits from sample_name
exampleTumourNormal %>%
mutate(group = stringr::str_remove(sample_name, "[0-9]")) %>%
qsea::getSampleTable()
#> sample_name group patient type tumour tissue age gender stage
#> Colon1_N Colon1_N Colon_N Colon1 NormalColon Normal Colon 80 F <NA>
#> Colon1_T Colon1_T Colon_T Colon1 CRC Tumour Colon 80 F III
#> Colon2_N Colon2_N Colon_N Colon2 NormalColon Normal Colon 67 F <NA>
#> Colon2_T Colon2_T Colon_T Colon2 CRC Tumour Colon 67 F IV
#> Lung1_N Lung1_N Lung_N Lung1 NormalLung Normal Lung 64 F <NA>
#> Lung1_T Lung1_T Lung_T Lung1 LUAD Tumour Lung 64 F IIA
#> Lung2_N Lung2_N Lung_N Lung2 NormalLung Normal Lung 71 F <NA>
#> Lung2_T Lung2_T Lung_T Lung2 LUSC Tumour Lung 71 F IA
#> Lung3_N Lung3_N Lung_N Lung3 NormalLung Normal Lung 72 M <NA>
#> Lung3_T Lung3_T Lung_T Lung3 LUAD Tumour Lung 72 M IB