【问题标题】:How to get a column data from my R object? [duplicate]如何从我的 R 对象中获取列数据? [复制]
【发布时间】:2014-12-10 18:33:17
【问题描述】:

我有一个如下的 R 对象。如何获取级别列数据? components$level 不起作用。我还给出了下面的属性。

> unclass(components)
            observed       level         slope       season1       season2
   [1,] 0.0084075449 0.007172836 -8.528225e-06  3.291206e-04 -8.909450e-04
   [2,] 0.0093858797 0.007214750 -8.594915e-06 -2.346916e-05 -8.712144e-04
   [3,] 0.0091792334 0.007257663 -8.663195e-06 -3.583402e-04 -8.507308e-04
   [4,] 0.0086728344 0.007292330 -8.718353e-06 -4.233460e-04 -8.295280e-04
   [5,] 0.0069083084 0.007293365 -8.720000e-06 -1.695487e-04 -8.076499e-04

> attributes(components)
$dim
[1] 1327    5

$dimnames
$dimnames[[1]]
NULL

$dimnames[[2]]
[1] "observed" "level"    "slope"    "season1"  "season2" 


$tsp
[1] 2011.00 2014.63  365.25

$class
[1] "mts"    "ts"     "matrix"

【问题讨论】:

  • components 是矩阵,而不是数据框,所以不能使用$ 访问列。试试components[,"level"]

标签: r object


【解决方案1】:

这有助于展示组件是如何初始化的,但我最好的猜测是

components[,'level']

【讨论】:

  • 第一个应该可以,但第二个不太可能。
  • 我不熟悉attributes(),我想也许$dimnames[[2]] 指的是别的东西,但在我看来它只是row=1,column=2,所以我会编辑
猜你喜欢
  • 2015-11-19
  • 1970-01-01
  • 1970-01-01
  • 2021-12-31
  • 1970-01-01
  • 1970-01-01
  • 2016-12-08
  • 1970-01-01
  • 2015-11-05
相关资源
最近更新 更多