【问题标题】:R: Extract list element but without index number in outputR:提取列表元素但输出中没有索引号
【发布时间】:2017-10-17 07:36:44
【问题描述】:

这似乎是一个初学者问题,但我无法在任何地方找到答案。我知道如何使用 listname[[1]] 从列表中提取元素,但输出将始终包含索引号,如

[1] First element of the list

使用 listname$name 或 unlist(listname$name) 之类的名称也是如此。我想要的只是

First element of the list

我当然可以使用正则表达式删除索引号,但我怀疑它应该是这样的:-)

【问题讨论】:

    标签: r


    【解决方案1】:

    [1] 出现的原因是因为 R 中的所有原子类型都是向量(字符、数字等类型),即在您的情况下,是长度为 1 的向量。

    如果您想查看没有[1] 的输出,最简单的方法是cat 对象:

    > listname <- list("This is the first list element", 
                       "This is the second list element")
    > cat(listname[[1]], "\n")
    This is the first list element 
    > 
    

    【讨论】:

    • 然后验证答案;)
    猜你喜欢
    • 2013-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-08
    • 2013-12-03
    • 2018-03-04
    • 2018-07-04
    • 1970-01-01
    相关资源
    最近更新 更多