R语言fread和read_delim读取数据
2017-11-03 本文已影响1709人
485b1aca799e
- data.table包中fread函数比readr包的函数读取更快,但是目前只能支持windows上的gbk编码与UTF-8编码
library(data.table)
timestart<-Sys.time()
x <- fread("D://data/vod/vod_month_201707.txt",sep = "\001",header = F,stringsAsFactors = F,encoding = "UTF-8",data.table = T)
timeend<-Sys.time()
runningtime<-timeend-timestart
print(runningtime)
#Time difference of 4.058793 secs
#结果显示消耗4秒
library(readr)
timestart <- Sys.time()
y <- read_delim("D://data/vod/vod_month_201707.txt",delim = "\001")
timeend <- Sys.time()
runningtime2 <- timeend-timestart
print(runningtime2)
#结果显示消耗Time difference of 5.136311 secs
x7 <- fread(input = paste("order_", year, month, ".txt", sep = ""),sep = "|",header = F,stringsAsFactors = F,data.table = T,encoding = "UTF-8",colClasses = c("numeric","character","character","character","character","character","character","character","character"))
colnames(x7) = c("city_id","userid","date","time","product_id","status","product_name","id","order_path")