2016年3月31日 星期四

[R] 匯入外部資料的方式

利用R分析資料時,根據不同的來源以及格式,有下列不同的匯入方式:


  • 讀取 table format 資料
    • read.table
      •         sep=",",header=F,col.names=c("age", "type_employer", "fnlwgt", "education",
                        "education_num","marital", "occupation", "relationship", "race","sex",
                        "capital_gain", "capital_loss", "hr_per_week","country", "income"),
                fill=FALSE,strip.white=T)
    • read.csv
    • read.csv2
    • read.delim
    • read.delim2
            使用說明如下:
             http://www.r-tutor.com/r-introduction/data-frame/data-import





  • 讀取其他系統的資料
    • MS-SQL
      • 需設定ODBC連線
      • 下載ODBC套件 安裝: install.packages("RODBC")library: library(RODB)請參考 : http://dofinotebook.blogspot.tw/2016/01/r-sql-server.html
    • EXCEL





https://stat.ethz.ch/R-manual/R-devel/library/utils/html/read.table.html