我希望能够创建一个返回3个列表的函数。例如:
Objects <- function(SetType, 2Type){
1Set <- list()
1Set$type <- SetType
2Set <- list()
2Set$type <- 2Type
3Set <- list()
return(1Set)
return(2Set)
return(3Set)
}
这只返回1Set。
我能想到的一种选择是创建两个简单地创建2Set和3Set的函数,然后在Objects函数中调用它们,但是有没有更好的方法来实现这一点?
发布于 2017-07-21 21:06:08
还要检查此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]]
https://stackoverflow.com/questions/45246634
复制