R 如何解释is()的输出?
当我在单个变量上调用R 如何解释is()的输出?,r,class,extend,superclass,R,Class,Extend,Superclass,当我在单个变量上调用is函数时,我得到了以下信息 > is(a) [1] "integer" "double" "numeric" [4] "vector" "data.frameRowLabels" ex <- extends("integer", fullInf
is
函数时,我得到了以下信息
> is(a)
[1] "integer" "double" "numeric"
[4] "vector" "data.frameRowLabels"
ex <- extends("integer", fullInfo=TRUE)
str(ex)
# List of 5
# $ double :Formal class 'SClassExtension' [package "methods"] with 10 slots
# .. ..@ subClass : chr "integer"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ superClass: chr "double"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ package : chr "methods"
# .. ..@ coerce :function (from, strict = TRUE)
# .. ..@ test :function (object)
# .. ..@ replace :function (from, to, value)
# .. ..@ simple : logi FALSE
# .. ..@ by : chr(0)
# .. ..@ dataPart : logi FALSE
# .. ..@ distance : num 1
# $ numeric :Formal class 'SClassExtension' [package "methods"] with 10 slots
# .. ..@ subClass : chr "integer"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ superClass: chr "numeric"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ package : chr "methods"
# .. ..@ coerce :function (from, strict = TRUE)
# .. ..@ test :function (object)
# .. ..@ replace :function (from, to, value)
# .. ..@ simple : logi TRUE
# .. ..@ by : chr(0)
# .. ..@ dataPart : logi FALSE
# .. ..@ distance : num 1
# $ vector :Formal class 'SClassExtension' [package "methods"] with 10 slots
# .. ..@ subClass : chr "integer"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ superClass: chr "vector"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ package : chr "methods"
# .. ..@ coerce :function (from, strict = TRUE)
# .. ..@ test :function (object)
# .. ..@ replace :function (from, to, value)
# .. ..@ simple : logi TRUE
# .. ..@ by : chr(0)
# .. ..@ dataPart : logi FALSE
# .. ..@ distance : num 1
# $ data.frameRowLabels:Formal class 'SClassExtension' [package "methods"] with 10 slots
# .. ..@ subClass : chr "integer"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ superClass: chr "data.frameRowLabels"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ package : chr "methods"
# .. ..@ coerce :function (from, strict = TRUE)
# .. ..@ test :function (object)
# .. ..@ replace :function (from, to, value)
# .. ..@ simple : logi TRUE
# .. ..@ by : chr(0)
# .. ..@ dataPart : logi FALSE
# .. ..@ distance : num 1
# $ integer : logi TRUE
这些信息告诉我们什么?为什么我们有三个不同的属性,例如[1]中的整数、双精度和数字
那么data.frameRowLabel
在这里意味着什么呢?调用is(object,class2)
而不使用第二个参数,我们可以得到对象(第一个元素)的类以及扩展(以下元素)
检查is(a)
的其他类的定义可以发现“integer”
是它们的一个子类
selectSuperClasses("integer") ## don't know why `"double"` isn't listed there...!
# [1] "numeric" "vector" "data.frameRowLabels"
getClassDef("data.frameRowLabels")
# Extended class definition ( "ClassUnionRepresentation" )
# Virtual Class "data.frameRowLabels" [package "methods"]
#
# No Slots, prototype of class "character"
#
# Known Subclasses:
# Class "character", directly
# Class "integer", directly
# Class "signature", by class "character", distance 2
# Class "className", by class "character", distance 2
# Class "ObjectsWithPackage", by class "character", distance 2
# Class "factor", by class "integer", distance 2
# Class "ordered", by class "integer", distance 3
## also try:
getClassDef("numeric")
getClassDef("vector")
getClassDef("double") ## lists `"integer"` as subclass
我们可以检查对象是否扩展到特定的类
is(a, "integer")
# [1] TRUE
is(a, "Date")
# [1] FALSE
## compare
is(Sys.Date(), "Date")
# [1] TRUE
扩展和模式是不同的东西:
is(a, "double")
# [1] TRUE
## but
is.double(a) ## tests the mode not the class resp. extend!
# [1] FALSE
为了测试对象和类之间的继承关系,我们可以使用扩展(class1,class2,maybe=TRUE,fullInfo=FALSE)
:
使用fullInfo=TRUE
给出所有is
-关系的完整定义。有关更多信息,请参阅
> is(a)
[1] "integer" "double" "numeric"
[4] "vector" "data.frameRowLabels"
ex <- extends("integer", fullInfo=TRUE)
str(ex)
# List of 5
# $ double :Formal class 'SClassExtension' [package "methods"] with 10 slots
# .. ..@ subClass : chr "integer"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ superClass: chr "double"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ package : chr "methods"
# .. ..@ coerce :function (from, strict = TRUE)
# .. ..@ test :function (object)
# .. ..@ replace :function (from, to, value)
# .. ..@ simple : logi FALSE
# .. ..@ by : chr(0)
# .. ..@ dataPart : logi FALSE
# .. ..@ distance : num 1
# $ numeric :Formal class 'SClassExtension' [package "methods"] with 10 slots
# .. ..@ subClass : chr "integer"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ superClass: chr "numeric"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ package : chr "methods"
# .. ..@ coerce :function (from, strict = TRUE)
# .. ..@ test :function (object)
# .. ..@ replace :function (from, to, value)
# .. ..@ simple : logi TRUE
# .. ..@ by : chr(0)
# .. ..@ dataPart : logi FALSE
# .. ..@ distance : num 1
# $ vector :Formal class 'SClassExtension' [package "methods"] with 10 slots
# .. ..@ subClass : chr "integer"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ superClass: chr "vector"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ package : chr "methods"
# .. ..@ coerce :function (from, strict = TRUE)
# .. ..@ test :function (object)
# .. ..@ replace :function (from, to, value)
# .. ..@ simple : logi TRUE
# .. ..@ by : chr(0)
# .. ..@ dataPart : logi FALSE
# .. ..@ distance : num 1
# $ data.frameRowLabels:Formal class 'SClassExtension' [package "methods"] with 10 slots
# .. ..@ subClass : chr "integer"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ superClass: chr "data.frameRowLabels"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ package : chr "methods"
# .. ..@ coerce :function (from, strict = TRUE)
# .. ..@ test :function (object)
# .. ..@ replace :function (from, to, value)
# .. ..@ simple : logi TRUE
# .. ..@ by : chr(0)
# .. ..@ dataPart : logi FALSE
# .. ..@ distance : num 1
# $ integer : logi TRUE
ex运行a
时返回的内容?如果您包含一个简单的示例输入和所需的输出,可用于测试和验证可能的解决方案,则会更容易为您提供帮助。您试图通过调用此函数来实现什么?可以使用is(1L)
extends("integer")
# [1] "integer" "double" "numeric"
# [4] "vector" "data.frameRowLabels"
ex <- extends("integer", fullInfo=TRUE)
str(ex)
# List of 5
# $ double :Formal class 'SClassExtension' [package "methods"] with 10 slots
# .. ..@ subClass : chr "integer"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ superClass: chr "double"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ package : chr "methods"
# .. ..@ coerce :function (from, strict = TRUE)
# .. ..@ test :function (object)
# .. ..@ replace :function (from, to, value)
# .. ..@ simple : logi FALSE
# .. ..@ by : chr(0)
# .. ..@ dataPart : logi FALSE
# .. ..@ distance : num 1
# $ numeric :Formal class 'SClassExtension' [package "methods"] with 10 slots
# .. ..@ subClass : chr "integer"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ superClass: chr "numeric"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ package : chr "methods"
# .. ..@ coerce :function (from, strict = TRUE)
# .. ..@ test :function (object)
# .. ..@ replace :function (from, to, value)
# .. ..@ simple : logi TRUE
# .. ..@ by : chr(0)
# .. ..@ dataPart : logi FALSE
# .. ..@ distance : num 1
# $ vector :Formal class 'SClassExtension' [package "methods"] with 10 slots
# .. ..@ subClass : chr "integer"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ superClass: chr "vector"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ package : chr "methods"
# .. ..@ coerce :function (from, strict = TRUE)
# .. ..@ test :function (object)
# .. ..@ replace :function (from, to, value)
# .. ..@ simple : logi TRUE
# .. ..@ by : chr(0)
# .. ..@ dataPart : logi FALSE
# .. ..@ distance : num 1
# $ data.frameRowLabels:Formal class 'SClassExtension' [package "methods"] with 10 slots
# .. ..@ subClass : chr "integer"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ superClass: chr "data.frameRowLabels"
# .. .. ..- attr(*, "package")= chr "methods"
# .. ..@ package : chr "methods"
# .. ..@ coerce :function (from, strict = TRUE)
# .. ..@ test :function (object)
# .. ..@ replace :function (from, to, value)
# .. ..@ simple : logi TRUE
# .. ..@ by : chr(0)
# .. ..@ dataPart : logi FALSE
# .. ..@ distance : num 1
# $ integer : logi TRUE