2

このデータセットは、次のコードを使用したwrite.zooを使用して作成されています。

z <- structure(c(9.82, 9.83, 9.82, 9.9, 9.81, 9.83, 12.57, 12.57, 
12.57, 12.57, 12.57, 12.57, 2.75, 2.74, 2.75, 2.67, 2.76, 2.74
), .Dim = c(6L, 3L), .Dimnames = list(c("15", "14", "13", "12", 
"11", "10"), c("depth", "from_sensor_to_river_bottom", "Depth_from_river_surface_to_bottom"
)), index = structure(c(1337810422, 1337811320, 1337812220, 1337813118, 
1337814021, 1337814919), class = c("POSIXct", "POSIXt"), tzone = ""), class = "zoo")

つまり、z動物園のオブジェクトです。

z
   depth from_sensor_to_river_bottom Depth_from_river_surface_to_bottom
15  9.82                       12.57                               2.75
14  9.83                       12.57                               2.74
13  9.82                       12.57                               2.75
12  9.90                       12.57                               2.67
11  9.81                       12.57                               2.76
10  9.83                       12.57                               2.74
attr(,"index")
[1] "2012-05-23 23:00:22 BST" "2012-05-23 23:15:20 BST" "2012-05-23 23:30:20 BST" "2012-05-23 23:45:18 BST"
[5] "2012-05-24 00:00:21 BST" "2012-05-24 00:15:19 BST"
attr(,"class")
[1] "zoo"

私はそれを使用してファイルに書き込みます:

 write.zoo(z, file = "y.txt", row.names=1:length(z[,1]),col.names=NULL)

出力ファイル「y.txt」は次のようになります。

 "Index" "depth" "from_sensor_to_river_bottom" "Depth_from_river_surface_to_bottom"
 "1" 2012-05-23 15:00:22 9.82 12.57 2.75
 "2" 2012-05-23 15:15:20 9.83 12.57 2.74
 "3" 2012-05-23 15:30:20 9.82 12.57 2.75
 "4" 2012-05-23 15:45:18 9.9 12.57 2.67
 "5" 2012-05-23 16:00:21 9.81 12.57 2.76

私はそれを使用してそれを読み込もうとしています:

 read.zoo("y.txt", tz="")

これは私にこのエラーを与えます:

  Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
  line 1 did not have 6 elements.

何が問題なのかわからないのですか?また、問題がファイルへの書き込みにあるのか、ファイルの読み取りにあるのか。

ご検討をお願いいたします。私はあなたの助けに感謝します。

4

2 に答える 2

2

この問題はタイムスタンプが原因で発生します。値は引用符で囲まれておらず、日付と時刻の間のスペースは列の区切り文字として誤って理解されています。

別の列区切り文字を使用すると、問題を回避できます。

write.zoo(z, file = "y.txt", sep="\t",
  row.names=1:length(z[,1]),col.names=NULL
)
read.zoo("y.txt", tz="", sep="\t")
于 2012-05-29T05:23:51.037 に答える
0

ヘッダーに1つの列名がありません。追加した後、chronライブラリをインストールしてこれを実行します

read.zoo( "zoo.txt"、FUN = as.chron)

于 2012-05-29T04:45:10.810 に答える