Rにcsvを読み込む時に出たエラー:incomplete final line found by readTableHeader on
どうでも良いけど、乾燥のせいか鼻の奥の方に嫌な予感のする痛みが出ています。 体調管理には気を付けたいところです。
さて朝からRにCSVを読み込もうとしてるけどエラーが出ています。
name | height | weight | sex |
---|---|---|---|
taro | 168.5 | 69.5 | M |
jiro | 172.8 | 75.0 | M |
hanako | 159.0 | 56.5 | F |
このような内容のcsvファイルを読み込むと、
> read.csv("data1.csv") name height weight sex 1 taro 168.5 69.5 M 2 jiro 172.8 75.0 M 3 hanako 159.0 56.5 F 警告メッセージ: In read.table(file = file, header = header, sep = sep, quote = quote, : incomplete final line found by readTableHeader on 'data1.csv'
こんなエラーというか警告がでます。で結局取り込めていない。
> data1 エラー: オブジェクト 'data1' がありません
調べてみて、いくつか対策してみたけど直らず。
解決しちゃいたいけど、出かける時間なので一旦、退散します。夜は忘年会なのでちょっと取り組むの遅くなりそうです。
追記
帰宅したので今朝引っかかった問題に取り組む。じつは読み込めていなかったわけではなく。読み込んだあとのデータ名を指定していなかったということでした。
> sample1 <- read="" csv="" data1="" :="" in="" table="" file="file," header="header," sep="sep," quote="quote," incomplete="" final="" line="" found="" by="" readtableheader="" on=""> sample1 name height weight sex 1 taro 168.5 69.5 M 2 jiro 172.8 75.0 M 3 hanako 159.0 56.5 F
sample1 <- read="" csv="" data1="" pre=""> でsample1にいれるということを明示しているわけですね。これ書かないと、エラーになるの当然だな。 警告に関してはstackoverflowを眺めてたらそれっぽいのありました。
readTableHead is the c-function that gives the error. It tries to read in the first n lines (standard the first 5 ) to determine the type of the data. The rest of the data is read in using scan(). So the problem is the format of the file.
確かに行数が多いのだと警告も出なかった。
> sample2 <- read="" csv="" data2=""> sample2 name height weight sex 1 taro 168.5 69.5 M 2 jiro 172.8 75.0 M 3 hanako 159.0 56.5 F 4 taro 168.5 69.5 M 5 jiro 172.8 75.0 M 6 hanako 159.0 56.5 F
さすがに眠いので寝ます。明日の朝はデータの扱い方をもう少し見ていきますかね。
参照:'Incomplete final line' warning when trying to read a .csv file into R