2017-06-16 160 views
0

我有一個.txt數據集,其中所述第一12行文本接着用2個空行,然後將數據fread爲什麼不接受skip命令?

DATE   HEIGHT INPUT  OUTPUT TESTMEASURE 
01/01/1933 NO RECORD NO RECORD MISSING  MISSING 
01/02/1933 NO RECORD NO RECORD MISSING  MISSING 

但是,當我做

dat <- fread('data.txt'), 

它將跳過15行,和用途第一條數據行作爲導入數據集的列名稱。它忽略標題行。

01/01/1933 NO RECORD NO RECORD MISSING  MISSING 

跳躍參數沒有影響我在導入所有。我如何提到需要用作列名的行號?或者我可以重命名列名,但不應該忽略第一行數據。

診斷

Input contains no \n. Taking this to be a filename to open 
File opened, filesize is 0.001319 GB. 
Memory mapping ... ok 
Detected eol as \r\n (CRLF) in that order, the Windows standard. 
Positioned on line 1 after skip or autostart 
This line is the autostart and not blank so searching up for the last non-blank ... line 1 
Detecting sep ... '\t' 
Detected 5 columns. Longest stretch was from line 15 to line 30 
Starting data input on line 15 (either column names or first row of data). First 10 characters: 01/01/1933 
The line before starting line 15 is non-empty and will be ignored (it has too few or too many items to be column names or data): DATE   HEIGHT INPUT OUTPUT TESTMEASURE the fields on line 15 are character fields. Treating as the column names. 
+0

它應該是'dat < - fread('data.txt',skip = 15)'? – CPak

+0

@ChiPak我需要跳過12 + 2 = 14行。但是,下面的任何內容,15,和數據集不受影響。 – maximusdooku

+0

無論我跳過什麼,導入的第一行都是01/02/1933。 – maximusdooku

回答

2

你有12行文字,2號線的空間,然後你的數據。但是我注意到DATEHEIGHT之間有額外的空白。所以作出這樣,你的數據是製表符分隔的文本文件,並添加2標籤DATEHEIGHT代替fread(data)之間1片

garbage 
garbage 
garbage 
garbage 
garbage 
garbage 
garbage 
garbage 
garbage 
garbage 
garbage 
garbage 


DATE  HEIGHT INPUT OUTPUT TESTMEASURE 
01/01/1933 NO RECORD NO RECORD MISSING MISSING 
01/02/1933 NO RECORD NO RECORD MISSING MISSING 

做給我:

fread(data) 
    01/01/1933 NO RECORD NO RECORD MISSING MISSING 
1: 01/02/1933 NO RECORD NO RECORD MISSING MISSING 

刪除DATEHEIGHT之間的額外選項卡給我:

  DATE HEIGHT  INPUT OUTPUT TESTMEASURE 
1: 01/01/1933 NO RECORD NO RECORD MISSING  MISSING 
2: 01/02/1933 NO RECORD NO RECORD MISSING  MISSING 
相關問題