普通情況下使用scan讀取數據
x <- scan("D:\\test.txt")按列讀入,指定數據類型
x <- scan("test2dat.txt", what=list("",0,0)) #讀取三列數據,第一列是字符,第二和第三列是數值
#以下寫法也可以
x2 <- scan("test2dat.txt", list(name="", num1=0,num2=0)) # 每個list都有個名字,分別為name,num1,num2可以指定讀取的行數,以下為讀取以逗號分割的csv文件的讀取方法
mydata <- read.table("test_nrow.txt.txt",sep=",", header=TRUE,nrow=5) #讀取除了表頭之外的5行數據參考: http://www.biostat.jhsph.edu/~rpeng/docs/R-large-tables.html
tab5rows <- read.table("datatable.txt", header = TRUE, nrows = 5)
classes <- sapply(tab5rows, class)
tabAll <- read.table("datatable.txt", header = TRUE, colClasses = classes)也可以用data.table 讀取大數據
install.packages("data.table")
library(data.table)
mydata <- fread("test.table.txt") #讀取文件時會顯示 Read **.*% of ***** rows, 讀取完畢會有提示
#查看文件的前6行
head(mydata)參考:http://www.r-bloggers.com/reading-large-data-tables-in-r/
也可以使用ff包
setwd("D:/data test")
library(ff)
ffdf1 <- read.table.ffdf(file = "test.ido", header = TRUE, sep = "|")參考: http://stackoverflow.com/questions/11782084/reading-in-large-text-files-in-r
http://www.bytemining.com/wp-content/uploads/2010/08/r_hpc_II.pdf
使用Python打開大數據的話,采用mmap
參考: http://stackoverflow.com/questions/11159077/python-load-2gb-of-text-file-to-memory
http://davetang.org/muse/2013/09/03/handling-big-data-in-r/
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。