我正在从Cowpertwait和Metcalfe的书中学习时间序列,"与R"一起介绍时间序列。这是电子书链接:http://unalmed.edu.co/~ndgirald/Archivos%20Lectura/Archivos%20curso%20Series%20EIO/notas%20series%20en%20r%20couperwait.pdf
我按照第20页的图书代码将12列的数据框转换为时间序列,将月份全球温度汇总到每年,然后绘制它,但它不起作用
以下是我收到的错误:Error in plotts(x = x, y = y, plot.type = plot.type, xy.labels = xy.labels, : cannot plot more than 10 series as "multiple"
以下是本书的代码,我还包括了他们网站上的数据集
global<-read.table("Chapter01global.txt",header=F)
global.ts = ts(global, st=c(1856,1), end=c(2005,12), fr=12)
global.annual = aggregate(global.ts, FUN=mean)
plot(global.ts); plot(global.annual)
这是我不明白的:
dim(global)
是150 12,但是
dim(global.ts)
是1800 12.难道它不是同一个维度吗?然后
dim(global.annual)
是150 12.不应该是150 1,因为平均值是在所有月份内接受的。
另外,我假设每个列都是每个月的全球温度,因为有150行,相当于1856年到2005年的年数。
有谁知道如何修复代码? Thaks
这是数据集:
-0.384 -0.457 -0.673 -0.344 -0.311 -0.071 -0.246 -0.235 -0.380 -0.418 -0.670 -0.386
-0.437 -0.150 -0.528 -0.692 -0.629 -0.363 -0.375 -0.328 -0.495 -0.646 -0.754 -0.137
-0.452 -1.031 -0.643 -0.328 -0.311 -0.263 -0.248 -0.274 -0.203 -0.121 -0.913 -0.197
-0.249 -0.041 -0.082 -0.172 -0.085 -0.278 -0.220 -0.132 -0.436 -0.234 -0.288 -0.486
-0.070 -0.526 -0.599 -0.420 -0.273 -0.063 -0.182 -0.256 -0.213 -0.326 -0.696 -0.813
-0.858 -0.415 -0.431 -0.443 -0.735 -0.169 -0.227 -0.131 -0.377 -0.375 -0.434 -0.209
-0.711 -0.817 -0.435 -0.232 -0.194 -0.322 -0.466 -0.623 -0.345 -0.382 -0.932 -0.768
0.263 -0.063 -0.379 -0.187 -0.320 -0.365 -0.510 -0.359 -0.291 -0.431 -0.362 -0.276
-0.834 -0.604 -0.516 -0.482 -0.399 -0.200 -0.138 -0.332 -0.394 -0.711 -0.507 -0.587
-0.125 -0.615 -0.597 -0.135 -0.152 -0.227 -0.153 -0.267 0.002 -0.358 -0.200 -0.324
0.095 -0.173 -0.396 -0.119 -0.533 0.078 -0.089 -0.282 -0.224 -0.364 -0.294 -0.368
-0.306 0.087 -0.665 -0.235 -0.452 -0.316 -0.267 -0.218 -0.073 -0.177 -0.317 -0.540
-0.718 -0.382 0.004 -0.281 -0.029 -0.113 0.067 -0.135 -0.234 -0.247 -0.517 -0.098
-0.159 0.241 -0.602 -0.232 -0.210 -0.372 -0.295 -0.228 -0.252 -0.581 -0.489 -0.487
-0.072 -0.462 -0.426 -0.246 -0.260 -0.242 -0.110 -0.216 -0.248 -0.352 -0.133 -0.729
-0.349 -0.528 -0.058 -0.157 -0.215 -0.216 -0.129 -0.218 -0.437 -0.505 -0.613 -0.643
-0.378 -0.385 -0.469 -0.163 -0.109 -0.117 -0.206 -0.146 -0.171 -0.269 -0.359 -0.385
-0.090 -0.397 -0.365 -0.414 -0.433 -0.187 -0.138 -0.183 -0.302 -0.541 -0.508 -0.397
-0.033 -0.407 -0.569 -0.573 -0.470 -0.300 -0.111 -0.342 -0.248 -0.476 -0.564 -0.425
-0.665 -0.673 -0.561 -0.457 -0.099 -0.162 -0.330 -0.233 -0.390 -0.463 -0.533 -0.493
-0.320 -0.361 -0.451 -0.407 -0.548 -0.387 -0.272 -0.239 -0.456 -0.465 -0.739 -0.812
-0.401 -0.085 -0.310 -0.442 -0.530 -0.155 -0.136 -0.165 -0.121 -0.157 -0.186 0.142
0.009 0.204 0.341 0.159 -0.125 -0.066 -0.134 -0.116 -0.113 -0.169 -0.274 -0.430
-0.244 -0.254 -0.145 -0.330 -0.279 -0.222 -0.166 -0.298 -0.220 -0.217 -0.537 -0.555
-0.108 -0.264 -0.300 -0.217 -0.334 -0.382 -0.280 -0.112 -0.274 -0.434 -0.557 -0.280
-0.506 -0.354 -0.231 -0.174 -0.020 -0.211 -0.029 -0.104 -0.221 -0.351 -0.497 -0.246
-0.070 -0.123 -0.070 -0.276 -0.266 -0.321 -0.221 -0.166 -0.252 -0.365 -0.489 -0.530
-0.480 -0.382 -0.437 -0.327 -0.317 -0.043 -0.146 -0.241 -0.335 -0.435 -0.348 -0.315
-0.402 -0.300 -0.362 -0.444 -0.345 -0.344 -0.243 -0.198 -0.290 -0.300 -0.559 -0.384
-0.551 -0.481 -0.343 -0.426 -0.386 -0.432 -0.268 -0.301 -0.241 -0.309 -0.311 -0.150
-0.340 -0.490 -0.339 -0.140 -0.061 -0.236 -0.138 -0.134 -0.202 -0.341 -0.362 -0.290
-0.439 -0.483 -0.363 -0.426 -0.262 -0.302 -0.151 -0.278 -0.259 -0.465 -0.365 -0.357
-0.629 -0.512 -0.556 -0.281 -0.301 -0.234 -0.265 -0.260 -0.139 -0.114 -0.218 -0.234
-0.195 -0.144 -0.142 -0.120 -0.036 -0.088 -0.200 -0.266 -0.270 -0.351 -0.436 -0.185
-0.347 -0.308 -0.334 -0.315 -0.454 -0.398 -0.406 -0.406 -0.466 -0.472 -0.596 -0.423
-0.583 -0.555 -0.422 -0.364 -0.256 -0.285 -0.312 -0.258 -0.167 -0.319 -0.537 -0.163
-0.477 -0.099 -0.453 -0.481 -0.407 -0.250 -0.397 -0.351 -0.232 -0.439 -0.571 -0.746
-1.032 -0.803 -0.386 -0.538 -0.518 -0.342 -0.185 -0.314 -0.300 -0.259 -0.368 -0.329
-0.422 -0.333 -0.370 -0.407 -0.435 -0.467 -0.342 -0.358 -0.500 -0.417 -0.474 -0.408
-0.567 -0.688 -0.465 -0.356 -0.353 -0.291 -0.384 -0.257 -0.205 -0.245 -0.274 -0.267
-0.241 -0.200 -0.412 -0.358 -0.096 -0.133 -0.145 -0.148 -0.155 -0.099 -0.311 -0.091
-0.290 -0.168 -0.323 -0.095 -0.011 -0.076 -0.111 -0.119 -0.105 -0.149 -0.414 -0.350
-0.053 -0.297 -0.770 -0.396 -0.398 -0.205 -0.269 -0.255 -0.258 -0.446 -0.461 -0.265
-0.247 -0.505 -0.518 -0.294 -0.250 -0.291 -0.173 -0.151 -0.115 -0.135 0.054 -0.404
-0.302 -0.269 -0.339 -0.250 -0.159 -0.067 -0.153 -0.173 -0.140 -0.038 -0.312 -0.089
-0.134 -0.255 -0.256 -0.144 -0.178 -0.149 -0.236 -0.238 -0.314 -0.325 -0.426 -0.436
-0.083 -0.149 -0.321 -0.423 -0.344 -0.329 -0.298 -0.353 -0.368 -0.449 -0.522 -0.544
-0.321 -0.136 -0.421 -0.445 -0.441 -0.473 -0.459 -0.492 -0.524 -0.532 -0.533 -0.575
-0.626 -0.546 -0.649 -0.561 -0.452 -0.403 -0.416 -0.373 -0.358 -0.350 -0.266 -0.330
-0.470 -0.679 -0.503 -0.549 -0.342 -0.288 -0.280 -0.265 -0.251 -0.342 -0.238 -0.233
-0.171 -0.319 -0.375 -0.182 -0.251 -0.226 -0.308 -0.238 -0.318 -0.300 -0.503 -0.312
-0.531 -0.531 -0.426 -0.604 -0.661 -0.556 -0.478 -0.459 -0.382 -0.363 -0.595 -0.483
-0.432 -0.465 -0.635 -0.515 -0.523 -0.379 -0.387 -0.446 -0.386 -0.516 -0.571 -0.490
-0.538 -0.514 -0.635 -0.572 -0.529 -0.444 -0.493 -0.285 -0.276 -0.291 -0.287 -0.516
-0.317 -0.435 -0.441 -0.404 -0.447 -0.460 -0.331 -0.386 -0.372 -0.468 -0.585 -0.640
-0.520 -0.612 -0.643 -0.666 -0.500 -0.466 -0.383 -0.372 -0.346 -0.409 -0.352 -0.273
-0.354 -0.260 -0.457 -0.347 -0.354 -0.251 -0.414 -0.507 -0.494 -0.573 -0.461 -0.399
-0.379 -0.464 -0.602 -0.471 -0.520 -0.516 -0.370 -0.302 -0.346 -0.394 -0.230 -0.133
-0.063 -0.194 -0.330 -0.368 -0.259 -0.198 -0.183 -0.270 -0.299 -0.140 -0.328 -0.360
-0.190 -0.004 -0.408 -0.050 -0.218 -0.104 -0.032 -0.159 -0.085 -0.265 -0.169 -0.248
-0.242 -0.237 -0.529 -0.339 -0.374 -0.433 -0.300 -0.250 -0.275 -0.310 -0.510 -0.658
-0.514 -0.785 -0.788 -0.503 -0.748 -0.374 -0.252 -0.319 -0.150 -0.411 -0.353 -0.787
-0.540 -0.557 -0.537 -0.541 -0.598 -0.324 -0.393 -0.417 -0.344 -0.137 -0.231 -0.269
-0.198 -0.157 -0.355 -0.104 -0.295 -0.232 -0.254 -0.289 -0.171 -0.305 -0.634 -0.484
-0.246 -0.414 -0.196 -0.275 -0.176 -0.265 -0.333 -0.238 -0.175 -0.304 -0.412 -0.443
-0.105 -0.242 -0.221 -0.180 -0.131 -0.149 -0.116 -0.304 -0.265 -0.197 -0.438 -0.238
-0.370 -0.350 -0.336 -0.321 -0.332 -0.311 -0.285 -0.285 -0.310 -0.332 -0.299 -0.325
-0.195 -0.463 -0.354 -0.452 -0.354 -0.262 -0.382 -0.433 -0.303 -0.224 -0.061 -0.058
-0.320 -0.308 -0.320 -0.406 -0.322 -0.265 -0.274 -0.287 -0.319 -0.330 -0.391 -0.565
-0.402 -0.291 -0.256 -0.263 -0.293 -0.282 -0.265 -0.172 -0.244 -0.328 -0.151 0.015
0.085 0.055 -0.011 -0.203 -0.235 -0.142 -0.195 -0.054 -0.122 -0.082 -0.215 -0.242
-0.256 -0.108 -0.347 -0.275 -0.278 -0.190 -0.135 -0.153 -0.114 -0.075 -0.205 -0.473
-0.128 -0.214 -0.400 -0.324 -0.259 -0.280 -0.187 -0.214 -0.170 -0.172 -0.133 -0.194
-0.430 -0.687 -0.388 -0.397 -0.389 -0.344 -0.349 -0.257 -0.260 -0.143 -0.093 -0.516
-0.354 -0.207 -0.188 -0.211 -0.233 -0.127 -0.105 -0.079 -0.130 -0.119 0.026 -0.095
0.007 -0.240 -0.122 -0.161 -0.163 -0.016 0.019 -0.061 -0.097 -0.061 -0.179 -0.084
0.126 -0.234 -0.307 -0.110 -0.207 -0.139 -0.110 -0.136 -0.030 -0.083 -0.232 -0.188
-0.276 -0.320 -0.322 -0.218 -0.195 -0.159 -0.132 -0.101 -0.188 -0.147 -0.313 -0.489
-0.221 -0.151 -0.371 -0.267 -0.090 -0.034 -0.060 -0.046 -0.141 -0.073 -0.056 -0.118
-0.286 0.171 -0.204 -0.302 -0.285 -0.184 -0.123 -0.122 -0.151 -0.036 -0.311 -0.216
-0.232 -0.366 -0.239 -0.236 -0.127 -0.086 0.019 -0.014 -0.068 -0.032 -0.046 -0.006
-0.154 0.080 -0.247 -0.167 -0.056 0.019 0.030 0.108 0.130 0.088 0.013 -0.128
0.032 0.062 0.147 0.150 0.053 0.032 0.124 0.053 0.124 0.197 0.096 -0.187
-0.042 -0.030 -0.218 -0.116 -0.035 0.094 0.028 0.044 -0.113 -0.207 -0.068 0.160
-0.402 -0.183 -0.184 -0.100 -0.122 0.016 0.134 -0.070 0.033 -0.077 -0.103 0.084
-0.040 0.037 -0.114 0.089 -0.050 0.054 0.066 0.028 -0.117 0.211 0.061 0.102
0.143 -0.104 -0.039 0.006 0.007 0.044 -0.084 -0.019 0.042 -0.018 -0.060 -0.124
-0.249 0.036 -0.221 -0.020 0.071 -0.063 0.082 -0.037 0.024 0.188 0.005 0.162
0.282 0.133 0.101 0.024 0.107 0.187 0.210 0.213 0.294 0.247 0.062 -0.011
0.036 0.037 0.003 0.161 -0.100 0.004 -0.018 0.301 0.107 0.134 -0.013 -0.189
0.084 0.094 -0.196 -0.002 -0.190 -0.241 -0.105 -0.197 -0.067 -0.041 -0.127 -0.383
-0.148 -0.186 -0.097 -0.071 -0.129 -0.064 -0.094 -0.086 -0.126 0.043 -0.014 -0.236
0.018 -0.147 -0.212 -0.091 0.005 -0.019 -0.140 -0.092 -0.093 -0.033 -0.096 -0.205
0.107 -0.201 -0.187 -0.043 -0.113 -0.150 -0.110 -0.043 -0.058 -0.060 -0.084 -0.230
-0.329 -0.274 -0.157 -0.209 -0.148 -0.119 -0.139 -0.165 -0.135 -0.170 -0.403 -0.237
-0.364 -0.462 -0.270 -0.157 -0.089 -0.053 -0.018 0.044 0.091 0.092 -0.036 0.106
0.106 0.069 -0.121 0.021 -0.007 0.008 0.003 0.018 0.018 -0.056 -0.218 -0.086
0.051 0.122 0.107 0.112 0.021 0.030 -0.039 0.015 0.047 0.056 -0.071 0.068
-0.221 -0.103 -0.186 -0.212 -0.254 -0.158 -0.254 -0.146 -0.107 -0.112 -0.021 -0.247
0.053 -0.169 -0.389 -0.290 -0.219 -0.188 -0.192 -0.075 -0.103 -0.115 -0.268 -0.320
-0.239 -0.379 -0.323 -0.326 -0.323 -0.261 -0.203 -0.242 -0.268 -0.195 -0.295 -0.248
-0.154 -0.103 -0.115 -0.066 0.013 0.050 -0.019 0.061 0.027 -0.002 0.083 0.168
0.275 0.174 0.065 0.046 0.045 0.001 0.049 0.017 -0.034 0.013 0.041 0.078
0.110 0.056 0.088 0.062 -0.010 0.053 0.033 -0.011 0.032 -0.061 -0.138 -0.055
-0.020 0.158 -0.296 -0.128 -0.133 0.009 0.006 0.009 0.042 -0.006 -0.118 0.136
0.028 0.134 0.055 0.069 0.077 0.066 -0.023 0.007 -0.023 -0.079 -0.049 -0.092
0.031 0.087 0.016 -0.020 -0.067 -0.062 -0.022 -0.017 -0.004 0.033 0.024 0.027
-0.042 0.166 -0.123 -0.053 -0.040 -0.021 0.061 0.100 0.085 0.155 0.110 0.016
-0.023 -0.158 -0.277 -0.246 -0.175 -0.185 -0.172 -0.255 -0.283 -0.342 -0.297 -0.414
-0.195 -0.290 -0.244 -0.273 -0.155 -0.129 -0.217 -0.127 -0.100 -0.055 -0.148 -0.078
-0.097 -0.080 -0.066 -0.132 -0.120 0.017 0.005 -0.057 -0.018 -0.119 -0.108 -0.218
-0.172 -0.269 -0.110 -0.094 0.019 -0.125 -0.112 -0.052 -0.096 0.071 -0.107 -0.134
-0.272 -0.227 0.015 -0.192 -0.209 -0.095 -0.068 -0.055 -0.053 -0.013 -0.050 -0.093
-0.178 -0.106 0.028 0.104 0.079 0.025 0.076 0.051 0.027 0.039 0.130 0.169
0.068 0.172 -0.040 0.043 -0.042 -0.013 -0.067 -0.079 -0.051 -0.096 -0.070 -0.215
-0.078 -0.309 -0.286 -0.236 -0.232 -0.246 -0.152 -0.129 -0.126 -0.148 -0.126 -0.206
-0.350 -0.286 -0.154 -0.065 -0.038 0.022 0.013 0.069 -0.002 0.052 0.016 0.173
0.187 0.263 0.237 0.137 0.129 0.128 0.074 0.028 -0.023 0.011 -0.071 -0.070
-0.301 -0.314 -0.194 -0.169 -0.146 -0.111 -0.065 -0.073 -0.140 -0.172 -0.174 -0.218
-0.077 -0.111 -0.092 -0.091 -0.038 -0.082 -0.082 -0.120 -0.066 -0.220 -0.264 -0.281
-0.197 -0.278 -0.391 -0.153 -0.258 -0.148 -0.156 -0.165 -0.129 -0.294 -0.166 -0.092
-0.112 0.088 0.140 0.122 0.060 0.123 0.051 0.019 0.067 0.017 0.140 -0.014
0.065 0.027 0.027 -0.030 -0.114 -0.130 -0.031 -0.120 -0.045 -0.092 0.011 -0.041
0.014 -0.121 0.006 -0.042 -0.023 0.078 0.036 0.114 0.128 0.159 0.138 0.334
0.129 0.148 0.047 0.138 0.203 0.126 0.067 0.056 0.040 0.032 0.162 0.056
0.304 0.202 0.227 0.159 0.067 0.077 0.042 0.090 0.072 0.035 0.074 0.254
-0.007 -0.025 -0.104 0.030 0.051 -0.021 -0.002 -0.011 0.077 0.039 -0.012 0.209
0.373 0.334 0.247 0.188 0.173 0.198 0.207 0.235 0.211 0.114 0.276 0.113
0.130 0.047 0.106 0.037 0.115 0.018 0.061 0.095 0.036 0.012 -0.078 -0.211
0.086 -0.093 0.010 -0.015 0.052 -0.033 -0.018 0.047 0.005 0.029 -0.016 0.086
0.198 0.185 0.120 0.109 0.102 0.116 0.055 0.053 0.076 0.077 -0.029 0.084
0.189 0.339 0.070 0.182 0.199 0.219 0.330 0.270 0.330 0.264 0.252 0.418
0.427 0.297 0.373 0.316 0.248 0.251 0.200 0.220 0.166 0.185 0.038 0.143
0.061 0.159 0.155 0.131 0.107 0.148 0.208 0.206 0.198 0.225 0.132 0.243
0.237 0.283 0.534 0.355 0.282 0.271 0.253 0.291 0.218 0.351 0.360 0.260
0.301 0.385 0.220 0.376 0.296 0.341 0.289 0.222 0.210 0.173 0.107 0.095
0.349 0.306 0.245 0.143 0.144 0.130 0.020 0.035 0.004 -0.021 -0.064 0.097
0.321 0.296 0.262 0.227 0.223 0.169 0.136 0.111 0.051 0.137 0.017 0.194
0.222 -0.032 0.223 0.243 0.244 0.224 0.185 0.224 0.239 0.327 0.361 0.331
0.462 0.558 0.373 0.319 0.281 0.369 0.387 0.415 0.323 0.350 0.361 0.280
0.163 0.343 0.217 0.164 0.256 0.274 0.281 0.228 0.189 0.165 0.166 0.278
0.254 0.348 0.324 0.295 0.299 0.431 0.422 0.444 0.517 0.538 0.488 0.572
0.512 0.824 0.593 0.660 0.613 0.639 0.704 0.670 0.475 0.452 0.345 0.469
0.404 0.607 0.283 0.357 0.296 0.328 0.340 0.287 0.324 0.280 0.197 0.383
0.203 0.429 0.388 0.469 0.304 0.267 0.250 0.365 0.304 0.219 0.123 0.172
0.343 0.307 0.505 0.432 0.456 0.415 0.447 0.502 0.407 0.390 0.523 0.348
0.641 0.680 0.620 0.445 0.429 0.449 0.488 0.395 0.439 0.395 0.423 0.301
0.545 0.430 0.393 0.397 0.450 0.440 0.454 0.518 0.521 0.573 0.429 0.573
0.508 0.619 0.527 0.469 0.295 0.358 0.364 0.436 0.452 0.494 0.586 0.385
0.502 0.355 0.512 0.553 0.494 0.516 0.537 0.510 0.526 0.514 0.493 0.305
答案 0 :(得分:1)
您的问题就在这里,您将ts
应用于由data.frame
而不是read.table
值产生的vector
:
global <- read.table("Chapter01global.txt",header=F)
global.ts = ts(global, st=c(1856,1), end=c(2005,12), fr=12)
比较他们的代码:
www = "http://web.address.that.doesnt.work.anymore.com"
global = scan(www)
#Read 1800 items
global.ts = ts(global, st=c(1856,1), end=c(2005,12), fr=12)
您的代码会产生:
str(global)
#'data.frame': 150 obs. of 12 variables: ...
他们的代码会生成一个向量,然后可以将其转换为正确的ts
对象:
str(global)
#num [1:1800] -0.384 -0.457 -0.673 -0.344 -...