Learn R Programming

MC2toPath (version 0.0.16)

SaveSequence: Save a sequence of yearly values

Description

Constructs a 2-column sequence of yearly values, and writes it to a text file.

Usage

SaveSequence(startYear, sequence, outFile)

Arguments

startYear
the calendar year of the first year in the sequence
sequence
an array of yearly values
outFile
the file name and path of the output file

Value

Examples

Run this code
## The function is currently defined as
function (startYear, sequence, outFile) 
{
    nSeq = length(sequence)
    stopifnot(nSeq >= 1)
    indexedSeq = matrix(0, nrow = nSeq, ncol = 2)
    appendFlag = FALSE
    for (ndx in 1:nSeq) {
        if (is.na(sequence[ndx])) 
            sequence[ndx] = 0
        cat(c(startYear + ndx - 1, ", ", sequence[ndx], "\n"), 
            file = outFile, append = appendFlag)
        appendFlag = TRUE
        indexedSeq[ndx, 1] = startYear + ndx - 1
        indexedSeq[ndx, 2] = sequence[ndx]
    }
    return(indexedSeq)
  }

Run the code above in your browser using DataLab