将描述性文本添加到变量

Bra*_*sen 8 r

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

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

Cha*_*ase 6

布兰登,

comment()并且attr()在这里很有用.这篇最近的帖子有一些非常好的信息.

从帮助页面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)
Run Code Online (Sandbox Code Playgroud)

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"
Run Code Online (Sandbox Code Playgroud)