การอ่านข้อมูลด้วย fread() อย่างรวดเร็ว

การจัดการข้อมูลด้วย data.table ใน R

Matt Dowle, Arun Srinivasan

Instructors, DataCamp

เร็วสุดๆ!

  • อ่านไฟล์แบบเร็วและขนาน
  • อาร์กิวเมนต์ nThread ควบคุมจำนวน thread ที่ใช้
การจัดการข้อมูลด้วย data.table ใน R

ใช้งานง่าย

  • รองรับไฟล์ในเครื่อง ไฟล์จากเว็บ และ string
  • ค่าเริ่มต้นอัจฉริยะ — colClasses, sep, nrows ฯลฯ
  • หมายเหตุ: วันที่และวันเวลาจะถูกอ่านเป็นคอลัมน์ character แต่สามารถแปลงภายหลังด้วยแพ็กเกจ fasttime หรือ anytime
การจัดการข้อมูลด้วย data.table ใน R

ตัวอ่านไฟล์ที่เร็วและใช้งานง่าย

# File from URL
DT1<-fread("https://bit.ly/2RkBXhV")
DT1
a b
1 2
3 4
# Local file
DT2 <- fread("data.csv")
DT2
a b
1 2
3 4
# String
DT3 <- fread("a,b\n1,2\n3,4")
DT3
a b
1 2
3 4
# String without col names
DT4 <- fread("1,2\n3,4")
DT4
V1 V2
1  2
3  4
การจัดการข้อมูลด้วย data.table ใน R

อาร์กิวเมนต์ nrows และ skip

# Read only first line (after header)
fread("a,b\n1,2\n3,4", nrows = 1)
a b
1 2
# Skip first two lines containing metadata
str <- "# Metadata\nTimestamp: 2018-05-01 19:44:28 GMT\na,b\n1,2\n3,4"
fread(str, skip = 2)
a b
1 2
3 4
การจัดการข้อมูลด้วย data.table ใน R

เพิ่มเติมเกี่ยวกับ nrows และ skip

str <- "# Metadata\nTimestamp: 2018-05-01 19:44:28 GMT\na,b\n1,2\n3,4"
fread(str, skip = "a,b")
a b
1 2
3 4
fread(str, skip = "a,b", nrows = 1)
a b
1 2
การจัดการข้อมูลด้วย data.table ใน R

อาร์กิวเมนต์ select และ drop

str <- "a,b,c\n1,2,x\n3,4,y"
fread(str, select = c("a", "c"))

# Same as
fread(str, drop = "b")
a c
1 x
3 y
str <- "1,2,x\n3,4,y"
fread(str, select = c(1, 3))

# Same as 
fread(str, drop = 2)
V1 V3
 1  x
 3  y
การจัดการข้อมูลด้วย data.table ใน R

มาฝึกกันเถอะ!

การจัดการข้อมูลด้วย data.table ใน R

Preparing Video For Download...