2017-07-21 66 views
0

多個列表我希望能夠創建一個返回3所列出的功能。例如:函數創建R中

Objects <- function(SetType, 2Type){ 
    1Set <- list() 
    1Set$type <- SetType 
    2Set <- list() 
    2Set$type <- 2Type 
    3Set <- list() 

    return(1Set) 
    return(2Set) 
    return(3Set) 
} 

這隻返回1Set。我能想到的

一種選擇是創建2個函數,只需創建2套和3設置,然後在對象函數呼籲他們,但有實現這一目標的一個更好的辦法?

+0

做到這一點'回報(名單(1套,2套,3設置))' – Wen

+0

這麼簡單,謝謝! –

+0

高興它幫助愉快的一天 – Wen

回答

1

還要檢查這個link

Objects <- function(SetType, 2Type){ 
    1Set <- list() 
    1Set$type <- SetType 
    2Set <- list() 
    2Set$type <- 2Type 
    3Set <- list() 

    return(list(1Set,2Set,3Set)) 
} 
Ret=Objects(SetType, 2Type) 
1Set=Ret[[1]] 
2Set=Ret[[2]] 
3Set=Ret[[3]]