2014-11-02 30 views
0

假設我有一個文本文件,data.txt中,含有如何在文本文件中的R已經在使用的列名

A B C D 
1 2 3 4 
5 6 7 8 

函數read.table使用,我得到:

> d = read.table('data.txt') 
> d 
    V1 V2 V3 V4 
1 A B C D 
2 1 2 3 4 
3 5 6 7 8 

如何我是否這樣做,而不是V1 V2 V3 V4出現,我得到文本文件中的列名?換句話說,我想有這樣的:

> d 
    A B C D 
1 1 2 3 4 
2 5 6 7 8 
+0

'read.table'有'header'參數默認設置爲'FALSE'。 – nrussell 2014-11-02 17:20:16

回答

3

你可以使用d <- read.table('data.txt', header=T)

相關問題