楼主: lutian08
5597 1

如何理解slot [推广有奖]

  • 0关注
  • 8粉丝

已卖:63份资源

副教授

53%

还不是VIP/贵宾

-

威望
0
论坛币
12013 个
通用积分
0.0816
学术水平
29 点
热心指数
33 点
信用等级
23 点
经验
7912 点
帖子
285
精华
0
在线时间
1423 小时
注册时间
2009-11-14
最后登录
2025-12-11

楼主
lutian08 发表于 2010-11-15 13:31:16 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
R中的slot该如何翻译,如何理解slot的功能和作用呢,对这不太明白
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:slot 如何理解 slot

沙发
DM小菜鸟 发表于 2015-1-16 00:24:54
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.
  
举个例子就是这样的 :
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

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"


这里有特别详细的说明文档:
http://stackoverflow.com/questions/4713968/r-what-are-slots
http://stat.ethz.ch/R-manual/R-devel/library/methods/html/slot.html
https://stat.ethz.ch/R-manual/R-devel/library/base/html/slotOp.html


比如:
setClass("track", representation(x="numeric", y="numeric"))
myTrack <- new("track", x = -4:4, y = exp(-4:4))
slot(myTrack, "x")
slot(myTrack, "y") <- log(slot(myTrack, "y"))
utils::str(myTrack)

getSlots("track") # or
getSlots(getClass("track"))
slotNames(class(myTrack)) # is the same as
slotNames(myTrack)



您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-22 09:51