【问题标题】:How to print the structure of an R object to the console如何将 R 对象的结构打印到控制台
【发布时间】:2012-04-16 23:55:12
【问题描述】:

打印 R 对象的结构以便可以通过运行打印输出重新创建对象的命令是什么?

输出通常包含structure 函数,您可以将输出复制并粘贴到您的代码中,以便为可重现的示例轻松创建对象。

我整个上午都在为这个我应该知道的命令而头疼。

【问题讨论】:

  • 这是一个很好的问题,发现dput 非常有帮助,但是这个问题的措辞使得通过谷歌很难找到它,因为它没有提供像“打印 R 对象以便可以将其复制并粘贴到您的代码中”。

标签: r


【解决方案1】:

函数是dput(或dump)。

【讨论】:

    【解决方案2】:

    我认为str 函数(又名结构)比转储具有更一致的有用信息。

    来自 R 帮助:

    Compactly Display the Structure of an Arbitrary R Object
    
    Description
    
    
    Compactly display the internal structure of an R object, a diagnostic function and an 
    alternative to summary (and to some extent, dput). Ideally, only one line for each 
    ‘basic’ structure is displayed. It is especially well suited to compactly display the 
    (abbreviated) contents of (possibly nested) lists. The idea is to give reasonable 
    output for any R object. It calls args for (non-primitive) function objects.
    

    【讨论】:

    • 这太棒了。
    • 为方便起见,RStudio 的“环境”选项卡显示str 的输出。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-15
    • 1970-01-01
    • 2016-12-27
    • 1970-01-01
    • 2014-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多