2017-07-21 52 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]]