2012-04-03 95 views
22

打印R对象结构的命令是什么,以便通过运行打印的输出可以重新创建对象?如何将R对象的结构打印到控制台

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

整天早上我对这个命令我应该知道的是,我一直在嘲笑我。

+3

这是一个很好的问题,发现'dput'一直是非常有帮助的,但这个问题的措辞使得它很难通过谷歌找到,因为它不会提出像“打印R对象,以便它可以复制并粘贴到代码中”的搜索。 – johneric 2015-10-17 20:33:44

回答

27

该功能是dput(或dump)。

8

我认为str功能(aka结构)比转储具有更一致有用的信息。

从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. 

相关问题