Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

dataframe

r

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 research information in a .Rdata file.

I want to add to my dataframe info like the one is displayed by ?iris (describing the data in the iris dataframe)

However I cannot find a way to do this.

like image 513
cyague Avatar asked Oct 27 '11 17:10

cyague


People also ask

How do I add records to a Dataframe in R?

To add row to R Data Frame, append the list or vector representing the row, to the end of the data frame. nrow(df) returns the number of rows in data frame. nrow(df) + 1 means the next row after the end of data frame. Assign the new row to this row position in the data frame.

How do I create a custom data frame in R?

How to Create a Data Frame. We can create a dataframe in R by passing the variable a,b,c,d into the data. frame() function. We can R create dataframe and name the columns with name() and simply specify the name of the variables.

What does as data frame () do in R?

as. data. frame() function in R Programming Language is used to convert an object to data frame. These objects can be Vectors, Lists, Matrices, and Factors.


1 Answers

@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.

like image 179
Josh O'Brien Avatar answered Sep 22 '22 17:09

Josh O'Brien