This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

## 
## Attaching package: 'dplyr'
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

You can also embed plots, for example: # 大同區

##       日期                 時間          場站代號        場站區域   
##  Min.   :2014-12-08   Min.   : 0.00   Min.   : 73.0   大同區 :8711  
##  1st Qu.:2014-12-17   1st Qu.: 6.00   1st Qu.: 79.0          :   0  
##  Median :2014-12-26   Median :12.00   Median :139.0   北投區 :   0  
##  Mean   :2014-12-25   Mean   :11.56   Mean   :121.3   大安區 :   0  
##  3rd Qu.:2015-01-03   3rd Qu.:18.00   3rd Qu.:145.0   蘆洲區 :   0  
##  Max.   :2015-01-11   Max.   :23.00   Max.   :183.0   南港區 :   0  
##                                                       (Other):   0  
##                   場站名稱         經度            緯度      
##  蔣渭水紀念公園       : 819   Min.   :25.05   Min.   :121.5  
##  捷運大橋頭站(2號出口): 819   1st Qu.:25.06   1st Qu.:121.5  
##  捷運雙連站(2號出口)  : 819   Median :25.06   Median :121.5  
##  捷運圓山站(2號出口)  : 819   Mean   :25.06   Mean   :121.5  
##  捷運中山站(4號出口)  : 819   3rd Qu.:25.07   3rd Qu.:121.5  
##  酒泉延平路口         : 819   Max.   :25.07   Max.   :121.5  
##  (Other)              :3797                                  
##     總停車格       平均車輛數      最大車輛數      最小車輛數    
##  Min.   :30.00   Min.   : 0.00   Min.   : 0.00   Min.   : 0.000  
##  1st Qu.:32.00   1st Qu.: 4.00   1st Qu.: 8.00   1st Qu.: 0.000  
##  Median :40.00   Median :10.43   Median :14.00   Median : 6.000  
##  Mean   :39.33   Mean   :11.70   Mean   :15.34   Mean   : 8.512  
##  3rd Qu.:46.00   3rd Qu.:17.64   3rd Qu.:21.00   3rd Qu.:15.000  
##  Max.   :52.00   Max.   :46.17   Max.   :51.00   Max.   :43.000  
##                                                                  
##   車輛數標準差      平均空位數       最大空位數      最小空位數   
##  Min.   : 0.000   Min.   : 0.333   Min.   : 2.00   Min.   : 0.00  
##  1st Qu.: 0.855   1st Qu.:18.900   1st Qu.:22.00   1st Qu.:15.00  
##  Median : 1.685   Median :26.345   Median :30.00   Median :23.00  
##  Mean   : 2.188   Mean   :27.188   Mean   :30.38   Mean   :23.55  
##  3rd Qu.: 2.929   3rd Qu.:35.766   3rd Qu.:39.00   3rd Qu.:32.00  
##  Max.   :19.204   Max.   :52.000   Max.   :52.00   Max.   :52.00  
##                                                                   
##   空位數標準差         氣溫           最高溫          最低溫     
##  Min.   : 0.000   Min.   :11.10   Min.   :12.26   Min.   :10.99  
##  1st Qu.: 1.000   1st Qu.:14.48   1st Qu.:15.83   1st Qu.:13.14  
##  Median : 2.000   Median :16.38   Median :17.66   Median :14.86  
##  Mean   : 2.188   Mean   :16.42   Mean   :17.80   Mean   :14.88  
##  3rd Qu.: 3.000   3rd Qu.:17.94   3rd Qu.:19.06   3rd Qu.:16.25  
##  Max.   :19.000   Max.   :24.53   Max.   :24.79   Max.   :20.35  
##                   NA's   :522     NA's   :522     NA's   :522    
##       溼度            氣壓         最大風速         降雨量       
##  Min.   :41.13   Min.   :1011   Min.   :0.002   Min.   : 0.0000  
##  1st Qu.:63.14   1st Qu.:1019   1st Qu.:1.823   1st Qu.: 0.0000  
##  Median :69.45   Median :1021   Median :2.407   Median : 0.0001  
##  Mean   :71.54   Mean   :1021   Mean   :2.411   Mean   : 0.3193  
##  3rd Qu.:80.83   3rd Qu.:1024   3rd Qu.:3.056   3rd Qu.: 0.0257  
##  Max.   :94.78   Max.   :1030   Max.   :5.124   Max.   :10.7956  
##  NA's   :522     NA's   :522    NA's   :522     NA's   :522      
##      星期                已借          無車機率         有車機率     
##  Length:8711        Min.   : 0.00   Min.   :0.0480   Min.   :0.0000  
##  Class :character   1st Qu.: 1.00   1st Qu.:0.6000   1st Qu.:0.0310  
##  Mode  :character   Median : 7.00   Median :0.8260   Median :0.1740  
##                     Mean   : 8.95   Mean   :0.7693   Mean   :0.2307  
##                     3rd Qu.:15.00   3rd Qu.:0.9690   3rd Qu.:0.4000  
##                     Max.   :45.00   Max.   :1.0000   Max.   :0.9520  
## 

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

# 產出一個欄位,紀錄是否為平日
bike.sub <- mutate(bike.sub, Workday = (星期 %in% 1:5))
#filter(bike.大同.s, 有車機率 == 0) %>% dim()
bike.sub$Workday <- as.factor(bike.sub$Workday)
levels(bike.sub$Workday) <- c("WEEKEND", "WORKDAY") 
bike.sub$Workday.v <- as.factor(as.numeric(bike.sub$Workday)) #workday 2, weekday 1

clean data

#clean data-------
naindex <- which(is.na(bike.sub$降雨量))
bike.clean <-bike.sub[-(naindex), ]

有無mrt

#有無mrt
MRT <- grep("捷運", bike.clean$場站名稱)
bike.clean$MRT <- rep(0, 8189)
bike.clean$MRT[MRT] <- 1  #有捷運的設為1
bike.clean$MRT <- as.factor(bike.clean$MRT)