2016-02-05 31 views
1

可以請有人告訴我如何可以將我的輸出作爲另一個函數的輸入調用兩個矩陣?如何調用另一個函數的結果R

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但都沒有奏效。任何tipps?

回答

2

您不能使用c,因爲有些人可能會這樣想,因爲您會失去矩陣的結構。如果要從R函數返回多個對象,請使用list

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