R-什麼是slot插槽?
阿新 • • 發佈:2019-01-08
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".
插槽Slots和S4物件型別相關。一個插槽可以被看作是一個部分,元素,或者物件的某個特性。比如你有一個物件是車,那麼你就有這些插槽:“價格”,“門的數量”,“發動機型別”,“里程數”。 舉例如下: 新建:
訪問:
Slots can be accessed in numerous ways :
插槽Slots和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
Anobject of class"Car"Slot"price":[1]20000Slot"numberDoors":[1]4Slot"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.訪問:
> [email protected]
[1]20000> slot(aCar,"typeEngine")[1]"V6"
Slots:The data contained in an objectfrom an S4 classisdefinedby the _slots_ in the class definition.Each slot in an objectis a component of the object; like
components (that is, elements ) of a list, these may be
extracted andset,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,notby position,and there isnopartial
matching of names aswith list elements.
注意:@插槽本身也可以是dataframe,插槽位置用@,之後的dataframe元素用$.
比如:par(bg=x@colors$bg.col,[email protected]$fg.col, xaxs='r',las=2,[email protected]$fg.col)