R:什么是老虎机? [英] R: what are Slots?
问题描述
有人知道R中的插槽吗?
Does anyone know what a slot is in R?
我没有找到其含义的解释.我得到一个递归定义: 插槽功能返回或设置有关对象各个插槽的信息"
I did not find the explanation of its meaning. I get a recursive definition: "Slot function returns or set information about the individual slots of an objects"
我们将不胜感激, 谢谢 - 胡同
Help would be appreciated, Thanks - Alley
推荐答案
插槽已链接到S4对象.插槽可以看作是对象的一部分,元素或属性".假设您有一个汽车物体,那么您可以拥有价格",门数",发动机类型",里程"等插槽.
Slots are linked to S4 objects. A slot can be seen as a part, element or a "property" of an object. Say you have a car object, then you can have the slots "price", "number of doors", "type of engine", "mileage".
在内部,它表示一个列表.一个例子:
Internally, that is represented a list. An example :
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类汽车"的插槽.这是一个简单的例子,实际上插槽本身又可以是复杂的对象.
Here, price, numberDoors, typeEngine and mileage are slots of the S4 class "Car". This is a trivial example, in reality slots themselves can be again complex objects.
可以通过多种方式访问插槽:
Slots can be accessed in numerous ways :
> aCar@price
[1] 20000
> slot(aCar,"typeEngine")
[1] "V6"
或通过构造特定方法(请参阅其他文档).
or through the construction of a specific method (see extra documentation).
有关S4编程的更多信息,请参见此问题.如果您仍然对这个概念感到困惑,那么对面向对象编程的一般介绍可能会有所帮助.
For more on S4 programming see this question. If the concept still sounds vague to you, a general introduction in Object Oriented Programming could help.
PS:请注意数据框和列表的区别,在其中使用$
访问命名变量/元素.
PS: Mind the difference with dataframes and lists, where you use $
to access named variables/elements.
这篇关于R:什么是老虎机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!