2015-12-01 50 views
0

讀txt文件,我有一個文本文件,但無法加載數據,由於下面的消息錯誤作爲R

tnf100m <- read.fwf("100mM.txt", widths = c(12,9,13,31,3,13,11,25,10), header = FALSE, col.names = c("ID","time","wind", "Name","country","birth","heat","Location","date"),stringsAsFactors = F) 

Error in substring(x, first, last) : 
      '<b1>0.0<20> Usain Bolt      JAM  21.08.86 1  Beijing     16.08.2008' 

100mM.txt如下所示:

1  9.58  +0.9 Usain Bolt JAM  21.08.86 1  Berlin   16.08.2009 
2  9.63  +1.5 Usain Bolt JAM  21.08.86 1  London     05.08.2012 
3  9.69  ?0.0 Usain Bolt JAM  21.08.86 1  Beijing     16.08.2008 

如何閱讀文本?

回答

0

如何更改widths的輸入值?

我可以使用widths = c(1,10,11,13,7,13,5,14,27)來讀取文件(包含您提供的文本的.txt文件)。

> read.fwf("D:/Users/perry/Downloads/100mM.txt", 
+   widths = c(1,10,11,13,7,13,5,14,27), 
+   header = FALSE, col.names = c("ID","time","wind", "Name","country","birth","heat","Location","date"), 
+   stringsAsFactors = F) 
    ID time  wind   Name country   birth heat  Location      date 
1 1 9.58  +0.9 Usain Bolt  JAM  21.08.86 1  Berlin     16.08.2009 
2 2 9.63  +1.5 Usain Bolt  JAM  21.08.86 1  London     05.08.2012 
3 3 9.69  ?0.0 Usain Bolt  JAM  21.08.86 1  Beijing     16.08.2008 
+0

謝謝。這有助於我清理數據。 –