在R中读取txt文件时出错
我有一个文本文件,但由于以下消息而无法加载数据在R中读取txt文件时出错,r,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,
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'
如何阅读文本?如何更改
宽度的输入值
我可以使用widths=c(1,10,11,13,7,13,5,14,27)
读取文件(包含您提供的文本的.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
> 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