在R中创建多个列表的功能

时间:2017-07-21 20:59:55

标签: r list

我希望能够创建一个返回3个列表的函数。例如:

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

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

这只返回1Set。

我能想到的一个选项是创建2个函数,只需创建2Set和3Set然后在Objects函数中调用它们,但是有更好的方法来实现它吗?

1 个答案:

答案 0 :(得分: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]]