SaveRatios: Normalize an array

Description Usage Arguments Value Author(s) Examples

View source: R/SaveRatios.R

Description

Transforms an array with a non-zero mean into an array of corresponding values normalized to the mean, and writes them out to a text file.

Usage

1
SaveRatios(rawValues, outFile)

Arguments

rawValues

the original array of values - must have a non-zero mean

outFile

the file name and path of the output file

Value

the normalized array

Author(s)

Dave Conklin

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## The function is currently defined as
function (rawValues, outFile) 
{
    nRaw = length(rawValues)
    stopifnot(nRaw >= 1)
    meanVal = mean(rawValues, na.rm = TRUE)
    stopifnot(meanVal != 0)
    ratios = rawValues/meanVal
    appendFlag = FALSE
    for (ndx in 1:nRaw) {
        if (is.na(ratios[ndx])) 
            ratios[ndx] = 0
        cat(c(ndx - 1, ", ", ratios[ndx], "\n"), file = outFile, 
            append = appendFlag)
        appendFlag = TRUE
    }
    return(ratios)
  }

Example output

function (rawValues, outFile) 
{
    nRaw = length(rawValues)
    stopifnot(nRaw >= 1)
    meanVal = mean(rawValues, na.rm = TRUE)
    stopifnot(meanVal != 0)
    ratios = rawValues/meanVal
    appendFlag = FALSE
    for (ndx in 1:nRaw) {
        if (is.na(ratios[ndx])) 
            ratios[ndx] = 0
        cat(c(ndx - 1, ", ", ratios[ndx], "\n"), file = outFile, 
            append = appendFlag)
        appendFlag = TRUE
    }
    return(ratios)
}

MC2toPath documentation built on May 2, 2019, 6:35 a.m.