[英]Error in read txt file in R
I Had a text file but failed to load the data due to the following message 我有一个文本文件,但由于以下消息而无法加载数据
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'
The 100mM.txt
looks like the following: 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
How to read the text? 如何阅读文字?
How about changing the input values of widths
? 如何更改
widths
的输入值?
I can read the file (a .txt file containing the text you provided) using widths = c(1,10,11,13,7,13,5,14,27)
. 我可以使用
widths = c(1,10,11,13,7,13,5,14,27)
读取文件(包含您提供的文本的.txt文件widths = c(1,10,11,13,7,13,5,14,27)
。
> 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.