readxl (1)

R 数据导入入门

Filip Schouwenaars

Instructor, DataCamp

Microsoft Excel

  • 常用数据分析工具
  • 许多 R 包可与 Excel 交互
  • readxl - Hadley Wickham
R 数据导入入门

Excel 数据的典型结构

  • 多个工作表,表格数据

Screen Shot 2019-07-15 at 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...