我有一个文本文件但由于以下消息而无法加载数据
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 :(得分: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