fread()로 빠른 데이터 읽기

R의 data.table로 데이터 조작하기

Matt Dowle, Arun Srinivasan

Instructors, DataCamp

매우 빠릅니다!

  • 빠른 병렬 파일 리더
  • nThread 인수로 사용할 스레드 수 제어
R의 data.table로 데이터 조작하기

사용자 친화적

  • 로컬 파일, 웹 파일, 문자열 모두 가져올 수 있음
  • 지능형 기본값 - colClasses, sep, nrows
  • 참고: 날짜 및 날짜/시간은 문자 열로 읽히지만, fasttime 또는 anytime 패키지로 이후에 변환 가능
R의 data.table로 데이터 조작하기

빠르고 편리한 파일 리더

# 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
R의 data.table로 데이터 조작하기

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
R의 data.table로 데이터 조작하기

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
R의 data.table로 데이터 조작하기

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
R의 data.table로 데이터 조작하기

연습해 봅시다!

R의 data.table로 데이터 조작하기

Preparing Video For Download...