【问题标题】:Adding Descriptive Text to a Variable向变量添加描述性文本
【发布时间】:2011-03-19 00:49:48
【问题描述】:

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

我发现,在某些情况下,对我的代码进行注释是不够的(尤其是在处理大量变量时)。

【问题讨论】:

    标签: r


    【解决方案1】:

    布兰登,

    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"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-19
      • 1970-01-01
      • 2012-01-31
      • 1970-01-01
      • 2016-04-14
      相关资源
      最近更新 更多