SaveSequence: Save a sequence of yearly values

Description Usage Arguments Value Author(s) Examples

View source: R/SaveSequence.R

Description

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

Usage

1
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

Returns a two-column matrix. The first column is the series of calendar years. The second column is the series of yearly values.

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 (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)
  }

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