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

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.

Value

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

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.

References

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

See also

Author

Alan Jassby, James Cloern

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)
#> Jan-Feb Feb-Mar Mar-Apr Apr-May May-Jun Jun-Jul Jul-Aug Aug-Sep Sep-Oct Oct-Nov #> 0.621 0.439 0.210 0.553 0.575 0.707 0.898 0.768 0.225 0.019 #> Nov-Dec Dec-Jan #> 0.979 0.352
# Convert to a data frame with October, the first month of the # local "water year", in the first column tsp(chl27)
#> [1] 1978.000 2009.583 12.000
chl27 <- round(chl27, 1) ts2df(chl27, mon1 = 10, addYr = TRUE)
#> Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep #> 1978 NA NA NA 1.1 2.8 5.6 2.7 3.4 1.9 1.6 NA 1.7 #> 1979 2.1 2.2 1.7 1.9 1.8 2.4 3.8 2.3 4.8 1.6 3.9 2.1 #> 1980 1.2 1.1 NA 1.3 1.9 2.1 10.2 3.4 2.1 1.1 1.4 1.6 #> 1981 1.4 1.7 1.3 NA 1.7 2.0 9.1 NA NA NA NA NA #> 1982 NA NA NA 2.8 4.5 6.5 9.3 8.2 3.4 1.4 NA 2.1 #> 1983 1.8 1.7 0.9 NA 1.4 7.0 16.4 16.6 5.4 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