How to add documentation to a data.frame in R?

前端 未结 3 694
后悔当初
后悔当初 2021-01-30 07:08

I\'ve been using R for a while and I\'ve realized it would help a lot if you could attach a description data contained in the data.frame, because you could gather all useful res

3条回答
  •  旧时难觅i
    2021-01-30 07:48

    @Spacedman has the good general answer for this sort of thing.

    If you'd like something a little fancier, you could try out comment().

     comment(iris) <- 
     "     This famous (Fisher's or Anderson's) iris data set gives the
     measurements in centimeters of the variables sepal length and
     width and petal length and width, respectively, for 50 flowers
     from each of 3 species of iris.  The species are _Iris setosa_,
     _versicolor_, and _virginica_.\n"
    
     cat(comment(iris))
     # This famous (Fisher's or Anderson's) iris data set gives the
     # measurements in centimeters of the variables sepal length and
     # width and petal length and width, respectively, for 50 flowers
     # from each of 3 species of iris.  The species are _Iris setosa_,
     # _versicolor_, and _virginica_.
    

    label() and units() from the in the Hmisc package provide mechanisms for documenting individual columns in data.frames. contents(), in the same package then summarizes any of these attributes you've attached to the data.frame.

提交回复
热议问题