## in-class exercise1 

db_AE <- as.Date("2019/9/1")
as.numeric(difftime(Sys.Date(), db_AE, unit="days"))
## [1] 264
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
startDate <- dmy("1-Sep-2019")
Sys.Date() - startDate
## Time difference of 264 days

## in-class exercise 2 

library(hrbrthemes)
## NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
##       Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
##       if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow
library(ggplot2)
dta <-read.csv("C:/Users/5A88/Desktop/calls_nyc.csv",h=T)
head(dta)
##   Hour Calls
## 1  0.5  1080
## 2  1.5   910
## 3  2.5   770
## 4  3.5   780
## 5  4.5   380
## 6  5.5   390
rt <- data.frame(Hour=as.numeric(seq(0,23,1)),
                 Calls=dta$Calls)
ggplot(rt, aes(Hour,
               Calls,
               group=1)) +
 geom_bar(width=1,
          stat="identity",
          fill="cyan",
          col="gray",
          alpha=0.2) +
 geom_abline(intercept=mean(rt$Calls),
             slope=0,
             col="red") +
 coord_polar(theta="x", 
             start=0) +
  scale_x_continuous(
    breaks = 0:23 - .5,
    labels = c(0,  rep('', 4), 5, rep('', 4), 10, rep('', 4),
               15, rep('', 4), 20, rep('', 3))) + 
 theme_ipsum()+
theme(panel.grid.minor.x = element_blank(),
        panel.grid.major.x = element_blank())
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database

## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

## in-class exercise 3

db <- as.Date("1984/08/22")
dd <- as.Date("2084/08/22")
as.numeric(difftime(dd, db, unit="days")) /365
## [1] 100.0685
bDays <- seq(from=db, to=dd, by="years")
table(weekdays(bDays))
## 
## 星期一 星期二 星期三 星期五 星期六 星期日 星期四 
##     14     15     14     14     15     14     15
plot(factor(weekdays(bDays), 
            levels = c("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"),
            labels = c("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")))

```