Skip to content

Instantly share code, notes, and snippets.

@sahilseth
Created October 7, 2015 16:08
Show Gist options
  • Save sahilseth/f8a7ed851dafe0e8064d to your computer and use it in GitHub Desktop.
Save sahilseth/f8a7ed851dafe0e8064d to your computer and use it in GitHub Desktop.
add complex variable names to a data.frame
df = data.frame(id = 1:10, fname = paste0("name", 1:10))
nms = c(id = "the unique id which does this or that",
fname = "first name of a person")
attr(df, 'info') <- nms
## let is see how this looks
attr(df, "info")
## show a pretty table
library(knitr) # OR library(params)
kable(df, col.names = attr(df, "info"))
@sahilseth
Copy link
Author

| the unique id which does this or that|first name of a person |
|-------------------------------------:|:----------------------|
|                                     1|name1                  |
|                                     2|name2                  |
|                                     3|name3                  |
|                                     4|name4                  |
|                                     5|name5                  |
|                                     6|name6                  |
|                                     7|name7                  |
|                                     8|name8                  |
|                                     9|name9                  |
|                                    10|name10                 |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment