我有予讀取使用下面的函數csv文件:跳過read.csv某些行中的R
csvData <- read.csv(file="pf.csv", colClasses=c(NA, NA,"NULL",NA,"NULL",NA,"NULL","NULL","NULL"))
dimnames(csvData)[[2]]<- c("portfolio", "date", "ticker", "quantity")
它讀取從該文件中的所有行。但我想從閱讀中跳過一些行。如果ticker
列的值爲:ABT
或ADCT
,則該行不應讀取。可能嗎?我的csv文件的
示例如下:
RUS1000,01/29/1999,21st Centy Ins Group,TW.Z,90130N10,72096,1527.534,0.01,21.188
RUS1000,01/29/1999,3com Corp,COMS,88553510,358764,16861.908,0.16,47.000
RUS1000,01/29/1999,3m Co,MMM,88579Y10,401346,31154.482,0.29,77.625
RUS1000,01/29/1999,A D C Telecommunicat,ADCT,00088630,135114,5379.226,0.05,39.813
RUS1000,01/29/1999,Abbott Labs,ABT,00282410,1517621,70474.523,0.66,46.438
RUS1000,02/26/1999,21st Centy Ins Group,TW.Z,90130N10,72096,1378.836,0.01,19.125
RUS1000,02/26/1999,3com Corp,COMS,88553510,358764,11278.644,0.11,31.438
RUS1000,02/26/1999,3m Co,MMM,88579Y10,402146,29783.938,0.29,74.063
使用'readLines'和使用正則表達式過濾掉不良行。 –
爲什麼不在以後讀整個文件和子集? – A5C1D2H2I1M1N2O1R2T1
實際上文件有200mb +,大部分數據都包含這些值。 –