按列表中元素名称的子集列表 [英] Subset list by name of element in list

查看:29
本文介绍了按列表中元素名称的子集列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有这样的列表:

x = rnorm(10)
y = rnorm(10)
df = cbind(x,y)
mylist=list(trace=df)

如何按名称提取跟踪 data.frame?我试过了

How can I pull out the trace data.frame by name? I've tried

trace_df = data.frame(mylist[mylist=='trace'])

但这会在列表中搜索等于 trace 的数据值,而不是搜索名为 list 的元素.

but this searches through the list for data values equal to trace not for elements named list.

我的想法是我有一个包含 7 或 8 个元素的大列表,它们的位置可能会改变.所以 trace 可能在索引点 1 或 2 或 5 中.所以为了使我的代码更具可重复性,我只想搜索术语 trace 而不是按索引搜索.

My thought behind this is that I have a large list of 7 or 8 elements and the position might change of them. So trace might be in index spot 1 or 2 or 5. So to make my code more reproducible I'd like to just search for the term trace and not search by index.

推荐答案

mylist$tracemylist[['trace']] 拉出来.

这篇关于按列表中元素名称的子集列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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