readxl (1)

การนำเข้าข้อมูลใน R เบื้องต้น

Filip Schouwenaars

Instructor, DataCamp

Microsoft Excel

  • เครื่องมือวิเคราะห์ข้อมูลยอดนิยม
  • R มีแพ็กเกจหลายตัวสำหรับทำงานกับ Excel
  • readxl - Hadley Wickham
การนำเข้าข้อมูลใน R เบื้องต้น

โครงสร้างทั่วไปของข้อมูล Excel

  • มีหลายชีตที่เก็บข้อมูลในรูปแบบตาราง

ภาพหน้าจอโครงสร้างข้อมูล Excel

การนำเข้าข้อมูลใน 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...