fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. TICKET<-read.csv("C:/Users/user/Desktop/票價.csv",header = F)
  4. #輸入資料,資料第一直欄為各車站中文站名,第二直欄為距離基隆站公里數
  5. Price<-function(from,to,yoyo){ #指定起站,迄站,是否使用悠遊卡
  6. if(yoyo==T){#使用悠遊卡時
  7.  
  8. x<-regexpr("from",TICKET[,1])#搜尋起站符合FROM資料集列數
  9. y<-regexpr("to",TICKET[,1])#搜尋迄站符合TO資料集列數
  10. z<-abs(TICKET$V2[x==1]-TICKET$V2[y==1])#計算兩站距離取絕對值
  11. p<-round((z-70)*2.27+70*2.27*0.9,1)#使用悠遊卡前70公里9折,其餘公里原價
  12.  
  13. }
  14. else{#不使用悠遊卡狀態
  15.  
  16. x<-regexpr("from",TICKET[,1])
  17. y<-regexpr("to",TICKET[,1])
  18. z<-abs(TICKET$V2[x==1]-TICKET$V2[y==1])
  19. p<-round(z*2.27,1)
  20.  
  21. }
  22. print(p)
  23. }
  24.  
  25.  
Success #stdin #stdout #stderr 0.16s 175424KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected '/' in "/"
Execution halted