軟體安裝順序

  1. Revolution R Open Math Library
  2. Revolution R Open (RRO)
  3. GitHub Desktop
  4. RStudio

RStudio教學與設定

RStudio教學

RStudio設定

  • Tools –> Global Options:
    • General: 確認R版本、預設工作目錄、文字檔編碼方式 Global Options–>General

    • Appearance: 設定程式碼字型、字型大小、風格主題 Global Options–>Appearance

    • Pane Layout: 設定四個子工作視窗要擺那些東西 Global Options–>Pane Layout

    • Packages: 設定Packages從哪裡下載、從MRAN下載要關掉HTTPS Global Options–>Packages

    • Git/SVN: 設定版本控制、Git.exe的檔案位址 Global Options–>Git/SVN

    • Publishing: 發布App到網頁、設定shinyapps.io的帳號 Global Options–>Publishing

R的Help文件與範例

help(read.csv) # or ?(read.csv)
## starting httpd help server ... done
??read.csv # or help.search(read.csv)
args(read.csv)
## function (file, header = TRUE, sep = ",", quote = "\"", dec = ".", 
##     fill = TRUE, comment.char = "", ...) 
## NULL
example(read.table)
## 
## rd.tbl> ## using count.fields to handle unknown maximum number of fields
## rd.tbl> ## when fill = TRUE
## rd.tbl> test1 <- c(1:5, "6,7", "8,9,10")
## 
## rd.tbl> tf <- tempfile()
## 
## rd.tbl> writeLines(test1, tf)
## 
## rd.tbl> read.csv(tf, fill = TRUE) # 1 column
##   X1
## 1  2
## 2  3
## 3  4
## 4  5
## 5  6
## 6  7
## 7  8
## 8  9
## 9 10
## 
## rd.tbl> ncol <- max(count.fields(tf, sep = ","))
## 
## rd.tbl> read.csv(tf, fill = TRUE, header = FALSE,
## rd.tbl+          col.names = paste0("V", seq_len(ncol)))
##   V1 V2 V3
## 1  1 NA NA
## 2  2 NA NA
## 3  3 NA NA
## 4  4 NA NA
## 5  5 NA NA
## 6  6  7 NA
## 7  8  9 10
## 
## rd.tbl> unlink(tf)
## 
## rd.tbl> ## "Inline" data set, using text=
## rd.tbl> ## Notice that leading and trailing empty lines are auto-trimmed
## rd.tbl> 
## rd.tbl> read.table(header = TRUE, text = "
## rd.tbl+ a b
## rd.tbl+ 1 2
## rd.tbl+ 3 4
## rd.tbl+ ")
##   a b
## 1 1 2
## 2 3 4
help(package = "base")
vignette(package = "e1071")
#得知e1071套件中有一名為"svmdoc"的vignette
vignette("svmdoc")
#以PDF viewer開啟svmdoc說明黨
#RSiteSearch("read.csv")
#install.packages("sos")
#library("sos")
#???acf

安裝R的Package

  1. 從RStudio介面安裝:
    Packages–>Install

  2. 下指令安裝,並指定Repository(當預設的Repository沒有要求的Package或特定版本,而必須另外指定時):

#install.packages("rmarkdown", repos = "http://cran.us.r-project.org", type = "source")
  1. 直接從GitHub安裝:
#require(devtools)
#install_github("wch/ggplot2")

R有6871個套件,我怎麼知道甚麼統計方法要用哪一個套件?

Ans: https://cran.r-project.org/web/views

#install.packages("ctv")
#library("ctv")
#install.views("TimeSeries")