Learn R Programming

SomaDataIO (version 6.2.0)

transform: Scale Transform soma_adat Columns/Rows

Description

Scale the i-th row or column of a soma_adat object by the i-th element of a vector. Designed to facilitate linear transformations of only the analyte/RFU entries by scaling the data matrix. If scaling the analytes/RFU (columns), v must have getAnalytes(adat, n = TRUE) elements. If scaling the samples (rows), v must have nrow(_data) elements.

Usage

# S3 method for soma_adat
transform(`_data`, v, dim = 2L, ...)

Value

A modified value of _data with either the rows or columns linearly transformed by v.

Arguments

_data

A soma_adat object.

v

A numeric vector of the appropriate length corresponding to dim.

dim

Integer. The dimension to apply elements of v to. 1 = rows; 2 = columns (default).

...

Currently not used but required by the S3 generic.

Details

Performs the following operations (quickly):

Columns: $$ M_{nxp} = A_{nxp} * diag(v)_{pxp} $$

Rows: $$ M_{nxp} = diag(v)_{nxn} * A_{nxp} $$

See Also

Examples

Run this code
# simplified example of underlying operations
M <- matrix(1:12, ncol = 4)
M

v <- 1:4
M %*% diag(v)    # transform columns

v <- 1:3
diag(v) %*% M    # transform rows

# dummy ADAT example:
v    <- c(2, 0.5)     # double seq1; half seq2
adat <- data.frame(sample      = paste0("sample_", 1:3),
                   seq.1234.56 = c(1, 2, 3),
                   seq.9999.88 = c(4, 5, 6) * 10)
adat

# `soma_adat` to invoke S3 method dispatch
class(adat) <- c("soma_adat", "data.frame")
trans <- transform(adat, v)
data.frame(trans)

Run the code above in your browser using DataLab