Nils
Nils

Reputation: 173

How to call a result from a function in another one in R

can please somebody tell me how I can call my output which are two matrices as an input into another function?

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
}

I tried return() and data.frame but both didn't work. Any tipps?

Upvotes: 1

Views: 162

Answers (1)

russellpierce
russellpierce

Reputation: 4711

You can't use c as some might otherwise expect because you'll lose the structure of the matrices. Instead, use list when you want to return multiple objects from an R function.

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

Upvotes: 2

Related Questions