splitting list into its components and combine to form another list in R [duplicate]

时光怂恿深爱的人放手 提交于 2021-02-11 16:47:50

问题


I have list 1:

l1 <- list(letters[1:26])

I have list 2:

l2 <- list(c(1:26))

How would I combine l1 and l2 into a new list l4 with 52 elements: the first 26 elements are the elements of l1 and the next 26 are the elements of l2?


回答1:


You could use c to combine them

l4 <- c(l1[[1]], l2[[1]])

Or with unlist

l4 <- c(unlist(l1), unlist(l2))

Maybe you want to wrap it in list

l4 <- list(c(l1[[1]], l2[[1]]))


来源:https://stackoverflow.com/questions/60229489/splitting-list-into-its-components-and-combine-to-form-another-list-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!