将描述性文本添加到变量

时间:2011-03-19 00:49:48

标签: r

是否有用于向变量添加描述性文本的命令或方法,以便在调用变量的str()时还会看到描述其中的内容的属性?

我发现,在某些情况下,评论我的代码是不够的(特别是在处理大量变量时)。

1 个答案:

答案 0 :(得分:6)

布兰登,

comment()attr()在这里很有用。 This recent post有一些非常好的信息。

来自comment()的帮助页面:

x <- matrix(1:12, 3,4)
comment(x) <- c("This is my very important data from experiment #0234",
                "Jun 5, 1998")
x
comment(x)

str(x)返回:

> str(x)
 int [1:3, 1:4] 1 2 3 4 5 6 7 8 9 10 ...
 - attr(*, "comment")= chr [1:2] "This is my very important data from experiment #0234" "Jun 5, 1998"