什么"at"符号@代表R?

Cin*_*ina 1 oop r s4

我想知道R中"@"(在符号处)的功能.
让我们说:
在下面的例子中,如果我调用perf1@x.values它开始显示全部x.values.但我无法通过调用访问x.values的第二个值perf@x.values[2]!

> str(perf1)
Formal class 'performance' [package "ROCR"] with 6 slots
  ..@ x.name      : chr "False positive rate"
  ..@ y.name      : chr "True positive rate"
  ..@ alpha.name  : chr "Cutoff"
  ..@ x.values    :List of 1
  .. ..$ : num [1:3966] 0 0.0005 0.001 0.0015 0.0015 0.002 0.0025 0.0025 0.003 0.0035 ...
  ..@ y.values    :List of 1
  .. ..$ : num [1:3966] 0e+00 0e+00 0e+00 0e+00 5e-04 5e-04 5e-04 1e-03 1e-03 1e-03 ...
  ..@ alpha.values:List of 1
  .. ..$ : num [1:3966] Inf 0.996 0.993 0.986 0.98 ...
Run Code Online (Sandbox Code Playgroud)

我想知道R中"@"符号的用法是什么?
以及如何使用@符号调用某些值?
谢谢

42-*_*42- 7

S4对象是带有节点或叶子的列表(技术上称为"插槽"),@操作员可以访问这些对象,就像访问S3对象一样$.

看一眼:

str( perf1@x.name )
str( perf1@y.name )
Run Code Online (Sandbox Code Playgroud)

请注意,这些可能包含普通的S3列表,如下所示:

str( perf1 @ x.values) # a list
str( perf1 @ x.values[[1]] ) # a numeric vector
perf1 @ x.values[[1]][1]   # the first value in `x.values`
Run Code Online (Sandbox Code Playgroud)

它被认为是不好的形式,因为S4对象的作者应该为你配备访问器功能,允许你获得任何有用的东西.