R中的结构和属性

问题描述 投票:6回答:1

我正在阅读Hadley的Advanced R一书。这本书有一个问题,这让我真的很困惑:

> structure(1:6, comment = "my attribute")
[1] 1 2 3 4 5 6

当您打印该对象时,看不到注释属性。为什么?该属性丢失了吗,还是还有其他特殊之处?

有人可以帮助我了解这里发生的事情吗?

r attributes structure
1个回答
9
投票
R的默认print方法对名为“ comment”的属性进行了特殊处理。从?comment

Description: These functions set and query a _comment_ attribute for any R objects. This is typically useful for ‘data.frame’s or model fits. Contrary to other ‘attributes’, the ‘comment’ is not printed (by ‘print’ or ‘print.default’).

© www.soinside.com 2019 - 2024. All rights reserved.