# Demonstrate the number of days in each category
barplot(table(mkfact(width="mon", y=2005)),
main="Number of days in each month")
barplot(table(mkfact(width="zod", y=2005)),
main="Number of days in each zodiac sign")
barplot(table(mkfact(width="DJF", y=2005)),
main="Number of days in each meteorological season")
barplot(table(mkfact(width=5, y=2005)),
main="Number of days in 5-day categories")
barplot(table(mkfact(width=11, y=2005)),
main="Number of days in 11-day categories")
barplot(table(mkfact(width=366/12, y=2005)),
main="Number of days in 12-section year",
sub="Note: not exactly the same as months")
# Application using synthetic data
dat <- data.frame(date=as.Date(paste(2005,1:365),"%Y %j"),
value=(-cos(1:365*2*pi/365)*10+rnorm(365)*3+10))
dat$d5 <- mkfact(dat,5)
dat$d11 <- mkfact(dat,11)
dat$month <- mkfact(dat,"mon")
dat$DJF <- mkfact(dat,"DJF")
plot(value ~ date, dat)
plot(value ~ d5, dat)
plot(value ~ d11, dat)
plot(value ~ month, dat)
plot(value ~ DJF, dat)
print(head(dat))
tapply(dat$value, dat$month, mean, na.rm=TRUE)
tapply(dat$value, dat$DJF, mean, na.rm=TRUE)
Run the code above in your browser using DataLab