R语言data.table包fread读取数据
R语言处理大规模数据速度不算快,通过安装其他包比如data.table可以提升读取处理速度。
案例,分别用read.csv和data.table包的fread函数读取一个1.67万行、230列的表格数据。
# 用read.csv读取数据
timestart<-Sys.time()data <- read.csv('XXXXs.csv',header = T,stringsAsFactors = F)timeend<-Sys.time()runningtime<-timeend-timestartprint(runningtime)# 返回 runningtime 结果: Time difference of 4.451127 secs
timestart<-Sys.time()data <- read.csv('XXXXs.csv',header = T,stringsAsFactors = F)timeend<-Sys.time()runningtime<-timeend-timestartprint(runningtime)# 返回 runningtime 结果: Time difference of 4.451127 secs
timestart<-Sys.time()data1<-fread('XXXXs.csv',header = T,stringsAsFactors = F)timeend<-Sys.time()runningtime<-timeend-timestartprint(runningtime) # 返回 runningtime 结果: Time difference of 0.9460249 secs
参考资料:
R语言data.table速查(博客园-Little_Rookie):https://www.cnblogs.com/nxld/p/6059570.html
https://zhuanlan.zhihu.com/p/22317779?refer=rdatamining
data.table的guideline: https://cran.r-project.org/web/packages/data.table/data.table.pdf
赞 (0)