readxl(1)

R 資料匯入入門

Filip Schouwenaars

Instructor, DataCamp

Microsoft Excel

  • 常見資料分析工具
  • 許多 R 套件可與 Excel 互動
  • readxl-Hadley Wickham
R 資料匯入入門

Excel 資料的典型結構

  • 不同工作表存放表格資料

螢幕截圖 2019-07-15 3.27.34 PM.png

R 資料匯入入門

readxl

  • excel_sheets()
    • 列出所有工作表
  • read_excel()
    • 將資料匯入 R
install.packages("readxl")
library(readxl)
R 資料匯入入門

excel_sheets()

dir()
"cities.xlsx"  "the_rest_is_secret.txt"
excel_sheets("cities.xlsx")
"year_1990" "year_2000"
R 資料匯入入門

read_excel()

read_excel("cities.xlsx")
# A tibble: 4 × 2
    Capital Population
      <chr>      <dbl>
1  New York   16044000
2    Berlin    3433695
3    Madrid    3010492
4 Stockholm    1683713
read_excel("cities.xlsx", sheet = 2)
read_excel("cities.xlsx", sheet = "year_2000")
# A tibble: 4 × 2
    Capital Population
      <chr>      <dbl>
1  New York   17800000
2    Berlin    3382169
3    Madrid    2938723
4 Stockholm    1942362
R 資料匯入入門

一起來練習吧!

R 資料匯入入門

Preparing Video For Download...