Learn R Programming

wq (version 0.4.8)

ts2df: 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)
monthCor(x)

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

eof

Examples

Run this code
# 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)

Run the code above in your browser using DataLab