[R] Variable labels
bobby@kn|ght @end|ng |rom gm@||@com
Sun May 16 05:52:01 CEST 2021
You make great sense wanting to have labels for your variables. When in
RStudio, the little arrow beside "mydata" in the Environment tab can be
clicked and you see all the variables there. And so you would like to see
a description under the variable names. Here is one way to accomplish
that. The following is not pseudocode, it's the actual code you should use.
Step 1, create a function that applies an attribute called "description" to
desc <- function(obj) attr(obj, "description")
Step 2, use attribute to apply the description
attr(mydata$invpc, "description") <- "Per capita inventory"
Step 3, Now you can either click the arrow beside "mydata" on the
environment tab and see that written description with the word
"description" in quotes. You can also type
And that will provide you the associated description in text form.
Robert D. Knight, MBA
Developer of Meal Plan and Grocery List maker for Android and iOS.
On Wed, May 12, 2021 at 9:49 PM Steven Yen <styen using ntu.edu.tw> wrote:
> I insert variable with the expss function as shown below. No error
> message. My question is, how to save the variable labels in the data
> frame so that I can click to read the labels. Thank you.
> year ="1947-1988",
> inv ="real housing inv, millions $",
> pop ="population, 1000s",
> price ="housing price index; 1982 = 1",
> linv ="log(inv)",
> lpop ="log(pop)",
> lprice ="log(price)",
> t ="time trend: t=1,...,42",
> invpc ="per capita inv: inv/pop",
> linvpc ="log(invpc)",
> gprice ="lprice - lprice_1",
> ginvpc ="linvpc - linvpc_1")
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help