如何在R中创建列表向量? [英] How to create a vector of lists in R?

查看:222
本文介绍了如何在R中创建列表向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表(tmpList),看起来像这样:

I have a list (tmpList), which looks like this:

$op
[1] "empty"

$termset
$termset$field
[1] "entry"

$termset[[2]]
$termset[[2]]$explode
[1] "Y"

这是一个列表,里面有一个列表. 如果我将此列表添加到向量中

This is a list with a list inside. If I add this list to a vector

theOneVector = c(theOneVector, tmpList)

现在,由于列表的第一个条目("op")与tmpList分开,因此所得向量的长度为2. 是否可以将完整的tmpList附加到此向量中?
我已经尝试过了

Now the resulting vector is of the length 2, because the first entry ("op") of the list is separated from the tmpList. Is it possible to append the complete tmpList into this vector?
I already tried it with

theOneVector = c(theOneVector, list(tmpList))

给出一个长度为1的向量,但是使用列表周围的这个额外列表来访问列表的元素非常麻烦. (我认为一句话中的清单太多.)

which gives a vector with the length of 1, but it is very cumbersome to access the elements of the list with this extra list around the list. (Too much list in one sentence I think.)

任何帮助将不胜感激,
马丁

Any help would be appreciated,
Martin

推荐答案

您可以将向量(所有组件必须为同一类型的受限结构)粘贴到列表中(不受限制).

You can stick a vector (a restricted structure where all components have to be of the same type) into a list (unrestricted).

但是您不能做相反的事情.使用列表列表中的列表...然后使用lapply等进行提取.

But you cannot do the reverse. Use lists of lists of lists ... and then use lapply et al to extract.

这篇关于如何在R中创建列表向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆