2012-04-03 93 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. 

相關問題