4

Is it possible to assign notes to a variable in an R dataframe? This is possible in Stata and SPSS.

Masood Sadat
  • 1,247
  • 11
  • 18
  • 3
    You can use the `comment()` function to add a note as an attribute. There's some additional info here: https://www.r-bloggers.com/adding-metadata-to-variables/ – Mako212 Sep 05 '19 at 16:00

1 Answers1

4

You can assign a comment as an attribute using the comment function.

x <- 1:5

# assign a comment
comment(x) <- 'this is a test comment'


# return a comment
comment(x)

[1] "this is a test comment"

str(x)

 int [1:5] 1 2 3 4 5
 - attr(*, "comment")= chr "this is a test comment"

Some additional info can be found here

Mako212
  • 6,787
  • 1
  • 18
  • 37