【问题标题】:How to call a result from a function in another one in R如何在 R 中调用另一个函数的结果
【发布时间】:2016-02-05 14:18:10
【问题描述】:

请有人告诉我如何调用我的输出,这两个矩阵作为另一个函数的输入?

X1=function(y,z)
{
 output1=y*z
 output2=y/z
}

X2=function(p,q)
{
 input=X1(y,z)
 input1=input$output1    ??? How to specify the output that I can call it this way? output1 and output2 are matrices!
 input2=input$output2
 equation=input1+input2
}

我尝试了return()data.frame,但都没有成功。有什么提示吗?

【问题讨论】:

    标签: r function extract


    【解决方案1】:

    您不能像某些人预期的那样使用c,因为您会丢失矩阵的结构。相反,当您想从 R 函数返回多个对象时,请使用 list

    X1 <- function(y,z)
    {
     list(
      output1=y*z,
      output2=y/z
     )
    }
    

    【讨论】:

      猜你喜欢
      • 2020-05-31
      • 1970-01-01
      • 2022-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-27
      相关资源
      最近更新 更多