addVarFromVar: Add a variable to a protdata object based on an existing...

View source: R/addVarFromVar.R

addVarFromVarR Documentation

Add a variable to a protdata object based on an existing column

Description

Adds a categorical variable to the data slot of a protdata object based on an exisiting variable.

Usage

addVarFromVar(protdata, basecol, name, vector)

Arguments

protdata

A protdata object of which the data slot needs to be expanded.

basecol

The name of the column in the existing data on which you base your new column.

name

The name of the new variable.

vector

A vector that contains the values of the new variable with names corresponding to all possible values of the basecol.

Value

A protdata object with an added column in its data slot containing the new variable.

Examples

#Here we show how the columns conc, rep and instrlab were added to the object proteinsCPTAC
data(proteinsCPTAC, package="MSqRob")
#Add a grouping factor for the spike-in condition (i.e. 6A, 6B, 6C, 6D and 6E)
conc <- factor(substr(levels(getData(proteinsCPTAC[1])$run), 11,12))
names(conc) <- levels(getData(proteinsCPTAC[1])$run)
proteinsCPTAC <- addVarFromVar(proteinsCPTAC,"run","conc",conc)

#Add a grouping factor for each of the 9 technical repeats (i.e. instrument x run)
rep <- factor(substr(levels(getData(proteinsCPTAC[1])$run), 14,14))
proteinsCPTAC <- addVarFromVar(proteinsCPTAC,"run","rep",rep)

#Add a grouping factor for the instrument effect (i.e. LTQ-Orbitrap at site 86, LTQ-Orbitrap O at site 65 and LTQ-Orbitrap W at site 56)
instrlab <- factor((as.numeric(rep)-1)%/%3+1)
proteinsCPTAC <- addVarFromVar(proteinsCPTAC,"run","instrlab",instrlab)

statOmics/MSqRob documentation built on Dec. 8, 2022, 6 a.m.