美文网首页R语言RNA-seq
R语言fread和read_delim读取数据

R语言fread和read_delim读取数据

作者: 485b1aca799e | 来源:发表于2017-11-03 22:36 被阅读1709次
    - 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")
    
    
    
    
    

    相关文章

      网友评论

        本文标题:R语言fread和read_delim读取数据

        本文链接:https://www.haomeiwen.com/subject/qnmxmxtx.html