如何将R对象的结构打印到控制台

时间:2012-04-03 10:27:09

标签: r

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

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

我整个上午都在打破这个我应该知道的命令。

2 个答案:

答案 0 :(得分:29)

该功能为dput(或dump)。

答案 1 :(得分:11)

我认为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.