Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.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
R 操纵S4类_R_S4 - Fatal编程技术网

R 操纵S4类

R 操纵S4类,r,s4,R,S4,c类可以简单地合并到a类中吗?如果是,怎么做?我搜索了文档和 我看了一个虚拟和超类。 我找不到任何关于合并类的内容 下面是创建类的代码- Example of the problem - class.a has slots 1, 2, 3 and inherits from class c (4, and 5). The slots in class (1, 2, 3) are passed to function.b as variables. the output of functi

c类可以简单地合并到a类中吗?如果是,怎么做?我搜索了文档和 我看了一个虚拟和超类。 我找不到任何关于合并类的内容

下面是创建类的代码-

Example of the problem - class.a has slots 1, 2, 3 
and inherits from class c (4, and 5).  
The slots in class (1, 2, 3) are passed to function.b as variables. 
the output of function b is as class.c.  So now I have the following.



class.a 
   slot 1  a value
   slot 2  a value
   slot 3  a value
   slot 4  empty
   slot 5  empty

   class.c
   slot 4 a result
   slot 5 a result
BondDetails是存储的信息 债券现金流使用债券明细的输入进行计算 债券期限结构使用债券明细和债券现金流的输入进行计算

我需要把它们都放到BondAnalytics中,这样我就可以创建一个输出方法,然后
似乎无法正确理解如何将这些代码转换为超类取决于其他700行代码的功能。。。默认情况下,S4类的
initialize
方法是一个复制构造函数,未命名的参数作为基类的实例。也许你的意思是你有这样的东西(我的类A、B、C与你的类不对应,但不知何故,命名似乎对我理解你的问题更有意义)

另一种可能是您已经有了一个“C”实例,并且您希望更新这些值以包含来自“B”实例的值


您可以重写函数b以获取类a的对象,将结果分配到插槽4和插槽5,然后再次返回该对象?可以将类设置为“继承”,但我看不到关于“合并”意味着什么能够回答此问题的充分解释。代码。。。。我们需要代码。大约有700行代码,涵盖了从S4对象传递变量的三个函数。我不知道这个软件怎么会发布在这里。通过合并,我的意思是我有一个名为slot的超类,它还继承了另外两个类。软件运行其他函数并为其他类(不是超级类)生成结果。所以,我认为这些类必须足够聪明,可以简单地插入正确的超类插槽。现在,我不这么认为,看起来它们必须一次分配一个,我认为你是对的,但让类彼此继承又有什么意义呢。只需设置一个大类(?)除非你有这样的情况,即拥有
类c
本身是有意义的,那么把它作为一个单独的父类是没有意义的。明白了,没错,我有一个a的实例,然后是b,我想创建c。谢谢-Glenntry尝试了初始化,但还是有点关闭。我有a、b和c班。超类包含a、b和c。a是存储值,b是使用a输入的函数调用的结果,c是使用a和b输入的函数调用的结果。我似乎无法创建超类。在这种情况下使用
?setClassUnion
是否有用?@ctbrown类联合用于创建一个将两个不相关的类层次结构联合起来的类,而这里所有的类似乎都在一个层次结构中。阶级联盟(对我来说)是非常奇怪的野兽,我很少使用它们。
setClass("BondDetails",
       representation(
       Cusip = "character",
       ID = "character",
       BondType = "character",
       Coupon = "numeric",
       IssueDate = "character",
       DatedDate = "character",
       StartDate = "character",
       Maturity = "character",
       LastPmtDate = "character",
       NextPmtDate = "character",
       Moody = "character",
       SP = "character",
       BondLab  = "character",
       Frequency = "numeric",
       BondBasis = "character",
       Callable = "character",
       Putable = "character",
       SinkingFund = "character"))

setClass("BondCashFlows",
     representation(
     Price = "numeric",
     Acrrued = "numeric",
     YieldToMaturity = "numeric",
     ModDuration = "numeric",
     Convexity = "numeric",
     Period = "numeric",
     PmtDate = "Date",
     TimePeriod = "numeric",
     PrincipalOutstanding = "numeric",  
     CouponPmt = "numeric",
     TotalCashFlow = "numeric"))

 setClass("BondTermStructure",
     representation(
     EffDuration = "numeric",
     EffConvexity = "numeric",
     KeyRateTenor = "numeric",
     KeyRateDuration = "numeric",
     KeyRateConvexity = "numeric"))

 setClass("BondAnalytics",
     contains = c("BondDetails","BondCashFlows", "BondTermStructure"))
.A <- setClass("A", representation(a="numeric"))
.B <- setClass("B", representation(b="numeric"))
.C <- setClass("C", contains=c("A", "B"))
a <- .A(a=1)
b <- .B(b=2)
> .C(a, b)              # Construct "C" from base classes "A" and "B"
An object of class "C"
Slot "a":
[1] 1

Slot "b":
[1] 2
b <- .B(b=2)
c <- .C(a=1, b=3)
> initialize(c, b)     # Copy c, replacing slots from 'B' with 'b'
An object of class "C"
Slot "a":
[1] 1

Slot "b":
[1] 2