ts2df: Convert time series to data frame

View source: R/ts2df.R

ts2dfR Documentation

Convert time series to data frame

Description

Convert monthly time series vector to a year x month data frame for several possible subsequent analyses. Leading and trailing empty rows are removed.

Usage

ts2df(x, mon1 = 1, addYr = FALSE, omit = FALSE)

Arguments

x

monthly time series vector

mon1

starting month number, i.e., first column of the data frame

addYr

rows are normally labelled with the year of the starting month, but addYr = TRUE will add 1 to this year number

omit

if TRUE, then rows with any NA will be removed.

Details

Our main use of ts2df is to convert a single monthly time series into a year x month data frame for EOF analysis of interannual variability.

monthCor finds the month-to-month correlations in a monthly time series x. It is useful for deciding where to start the 12-month period for an EOF analysis (mon1 in ts2df), namely, at a time of low serial correlation in x.

Value

An n x 12 data frame, where n is the number of years.

Author(s)

Alan Jassby, James Cloern

References

Craddock, J. (1965) A meteorological application of principal component analysis. Statistician 15, 143–156.

See Also

eof

Examples


# San Francisco Bay station 27 chlorophyll has the lowest serial 
# correlation in Oct-Nov, with Sep-Oct a close second
chl27 <- sfbayChla[, 's27']
monthCor(chl27)

# Convert to a data frame with October, the first month of the 
# local "water year", in the first column
tsp(chl27)
chl27 <- round(chl27, 1)
ts2df(chl27, mon1 = 10, addYr = TRUE)
ts2df(chl27, mon1 = 10, addYr = TRUE, omit = TRUE)


wql documentation built on Aug. 10, 2022, 5:06 p.m.