How to combine two lists in R

前端 未结 3 1600
长情又很酷
长情又很酷 2020-12-04 18:37

I have two lists:

l1 = list(2, 3)
l2 = list(4)

I want a third list:

list(2, 3, 4).

How can I do it in sim

3条回答
  •  被撕碎了的回忆
    2020-12-04 19:06

    I was looking to do the same thing, but to preserve the list as a just an array of strings so I wrote a new code, which from what I've been reading may not be the most efficient but worked for what i needed to do:

    combineListsAsOne <-function(list1, list2){
      n <- c()
      for(x in list1){
        n<-c(n, x)
      }
      for(y in list2){
        n<-c(n, y)
      }
      return(n)
    }
    

    It just creates a new list and adds items from two supplied lists to create one.

提交回复
热议问题