Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oop R:什么是吃角子老虎机?_Oop_R_S4_Slot_R Faq - Fatal编程技术网

Oop R:什么是吃角子老虎机?

Oop R:什么是吃角子老虎机?,oop,r,s4,slot,r-faq,Oop,R,S4,Slot,R Faq,有人知道R中的插槽是什么吗 我没有找到它的意思的解释。我得到一个递归定义: “Slot函数返回或设置有关对象的各个插槽的信息” 我们将不胜感激, 谢谢- 通道插槽链接到S4对象。插槽可以看作是对象的一部分、元素或“属性”。假设你有一个汽车对象,那么你就可以有“价格”、“车门数量”、“发动机类型”、“里程”等栏位 在内部,这是一个列表。例如: setClass("Car",representation=representation( price = "numer

有人知道R中的插槽是什么吗

我没有找到它的意思的解释。我得到一个递归定义: “Slot函数返回或设置有关对象的各个插槽的信息”

我们将不胜感激, 谢谢-
通道

插槽链接到S4对象。插槽可以看作是对象的一部分、元素或“属性”。假设你有一个汽车对象,那么你就可以有“价格”、“车门数量”、“发动机类型”、“里程”等栏位

在内部,这是一个列表。例如:

setClass("Car",representation=representation(
   price = "numeric",
   numberDoors="numeric",
   typeEngine="character",
   mileage="numeric"
))
aCar <- new("Car",price=20000,numberDoors=4,typeEngine="V6",mileage=143)

> aCar
An object of class "Car"
Slot "price":
[1] 20000

Slot "numberDoors":
[1] 4

Slot "typeEngine":
[1] "V6"

Slot "mileage":
[1] 143
或者通过构造特定的方法(参见附加文档)

有关S4编程的更多信息,请参阅。如果这个概念听起来仍然很模糊,那么对面向对象编程的一般介绍可能会有所帮助


PS:请注意数据帧和列表的区别,在数据帧和列表中,您可以使用
$
访问命名变量/元素。

除了@Joris指向您的资源,再加上他自己的答案,请尝试阅读
?类,其中包括插槽上的以下内容:

 Slots:

      The data contained in an object from an S4 class is defined
      by the _slots_ in the class definition.

      Each slot in an object is a component of the object; like
      components (that is, elements) of a list, these may be
      extracted and set, using the function ‘slot()’ or more often
      the operator ‘"@"’.  However, they differ from list
      components in important ways.  First, slots can only be
      referred to by name, not by position, and there is no partial
      matching of names as with list elements.
      ....
正如
names(variable)
列出了复杂变量的所有
$
可访问的名称一样,也是如此

slotNames(对象)
列出对象的所有插槽


很容易发现你的fit对象包含了什么样的好东西来满足你的观看乐趣。

不知道为什么R必须重新定义一切。大多数普通编程语言称它们为“属性”或“属性”

这是来自
slot()
函数的帮助-它不是用来记录slot是什么,只是记录如何访问它们。+1回答很好Joris。您可能需要添加一个
slot(aCar,“price”)
示例,作为另一个用法,尤其是在op正在查看
slot()
函数时。谢谢,您的回答非常有用!!要获取一个类的所有插槽,它们的名称有
getSlots()
,或
slotNames()
。这是一个合法的注释。让我们承认R充满了诡异的设计选择。我可以理解70年代的特性的奇怪术语,但插槽不在其中,它们实际上是在大多数OO语言落后几十年的时候添加的。
 Slots:

      The data contained in an object from an S4 class is defined
      by the _slots_ in the class definition.

      Each slot in an object is a component of the object; like
      components (that is, elements) of a list, these may be
      extracted and set, using the function ‘slot()’ or more often
      the operator ‘"@"’.  However, they differ from list
      components in important ways.  First, slots can only be
      referred to by name, not by position, and there is no partial
      matching of names as with list elements.
      ....