data(dataFranses1996)
class(dataFranses1996) # [1] "mts" "ts" "matrix"
pcfr <- pcts(dataFranses1996)
class(pcfr) # "PeriodicMTS"
nSeasons(pcfr) # 4
allSeasons(pcfr)
allSeasons(pcfr, abb = TRUE)
## subsetting
## one index, x[i], is analogous to lists
pcfr2to4 <- pcfr[2:4]; class(pcfr2to4) # "PeriodicMTS"
pcfr2to2 <- pcfr[2]; class(pcfr2to2) # "PeriodicMTS"
pcfr2 <- pcfr[[2]]; class(pcfr2) # note '[[', "PeriodicTS"
## data for 1990 quarter 3
pcfr2to4[as_date("1990-07-01")] # note: not "1990-03-01"!
pct1990_Q3 <- Pctime(c(1990, 3), pcCycle(pcfr2to4))
pcfr2to4[pct1990_Q3]
## with empty index, returns the underlying data
dim(pcfr[]) # [1] 148 19
dim(pcfr2to2[]) # 148 1
length(pcfr2[]) # 148 (this is numeric)
summary(pcfr2)
summary(pcfr2to4)
## make the output width shorter
summary(pcfr2to4, row.names = FALSE)
summary(pcfr2to4, row.names = 5) # trim row names to 5 characters
head(pcfr2to4) # starts with NA's
tail(pcfr2to4) # some NA's at the end too
## time of first and last data, may be NA's
start(pcfr2to4) # 1955 Q1
end(pcfr2to4) # 1991 Q4
## time of first nonNA:
availStart(pcfr2) # 1955 Q1
availStart(pcfr2to4) # 1955 Q1
## time of last nonNA:
availEnd(pcfr[[2]]) # 1991 Q4
availEnd(pcfr[[3]]) # 1987 Q4
availEnd(pcfr[[4]]) # 1990 Q4
## but at least one of them is available for 1991 Q4, so:
availEnd(pcfr2to4) # 1991 Q4
## use window() to pick part of the ts by time:
window(pcfr2to4, start = c(1990, 1), end = c(1991, 4))
## drop NA's at the start and end:
window(pcfr2to4, start = availStart(pcfr2to4), end = availEnd(pcfr2to4))
plot(pcfr2) # the points mark the first season in each cycle
boxplot(pcfr2)
monthplot(pcfr2)
Run the code above in your browser using DataLab