2012-07-24 39 views
1

這裏是我的簡單的文本(名爲test):R的read.table中''和''之間的區別是什麼?

name  sex  age height 
1 x1  F  18 162 
2 x2  M  19 170 
3 x3  M  21 178 
4 x4  F  22 166 
5 x5  F  23 165 

>read.table('test', sep='') 

這沒關係。

>read.table('test', sep=' ') 

Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : 
    line 1 did not have 20 elements 

我想知道爲什麼。

R的read.table中的''和''有什麼區別?請告訴我原因。

回答

6

如文檔中解釋的,''默認值意味着「空白的任何金額」,而你的第二個選擇' '意味着正是一個空間這實際上是非常不同的。

的措辭(在help(read.table))是不理想,但能夠完成任務:

sep: the field separator character. Values on each line of the 
     file are separated by this character. If ‘sep = ""’ (the 
     default for ‘read.table’) the separator is ‘white space’, 
     that is one or more spaces, tabs, newlines or carriage 
     returns. 

你想要的默認值,除非你知道你有,比如說,用逗號分隔的csv文件。

相關問題