0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

R > error > line 1 did not have 920 elements > 途中の行で列数が合わない

Last updated at Posted at 2016-09-11
動作環境
RStudio 0.99.903 on Windows 7 pro
R version 3.3.1 
> xtmp<-read.table("excel.csv",sep=",")
Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  : 
  line 1 did not have 920 elements

参考 http://stackoverflow.com/questions/18161009/error-in-reading-in-data-set-in-r

stackoverflowを見ると、どうもタイトル(920項目)とデータの行(line 1?)の列数が合わないようだ。

実際にexcel.csvを見ると、データの部分を空白にしているなどある。

空白を埋めるなどすればいいのだろうが、使いたい列のデータ(全行にデータがあると仮定)をExcelで切り出して使う方が楽そうだ。

確認

error.csv
1,2,3
2,2,3
3,3
4,4
5,5

に対して

> xtmp<-read.table("error.csv",sep=",")
Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  : 
  line 3 did not have 3 elements

3,3の部分でエラーが出た。これと同じことがexcel.csvにて発生している。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?