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.
mydata<-read_excel("data/Excel/hseinv.xlsx",na=".")
library(expss)
mydata=apply_labels(mydata,
??????????????????? 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)",
??????????????????? lprice_1="lprice[_n-1]",
??????????????????? linvpc_1="linvpc[_n-1]",
??????????????????? gprice? ="lprice - lprice_1",
??????????????????? ginvpc? ="linvpc - linvpc_1")
Variable labels
7 messages · Fredrik Karlsson, PIKAL Petr, Robert Knight +1 more
Hi, I am sorry but I don't understand your question, Generally, "clicking" is not something you can assume to be implemented for anything in R. However, if you read the manual for the package https://gdemin.github.io/expss/ you get an example at the bottom where an illustration of how the package can be used to create Excel tables which would then be easy to interact with through clicking. Is that what you wanted? Fredrik
On Thu, May 13, 2021 at 4:49 AM Steven Yen <styen at 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.
mydata<-read_excel("data/Excel/hseinv.xlsx",na=".")
library(expss)
mydata=apply_labels(mydata,
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)",
lprice_1="lprice[_n-1]",
linvpc_1="linvpc[_n-1]",
gprice ="lprice - lprice_1",
ginvpc ="linvpc - linvpc_1")
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
"Life is like a trumpet - if you don't put anything into it, you don't get anything out of it." [[alternative HTML version deleted]]
Thanks. What I need ?appears? simple. The .RData file is provided by a third party (likely converted from a different data format such as SAS in which variable labels (not value labels) are common). When I load the binary file, in the ?environment? I see, as expected, a data frame showing how many observations for how many variables. In addition, there is also an item (in the environment) (say ?desc?) containing a list of variable labels (definitions). I simply like to know how to get ?desc? in the environment?-it is a convenient way to show definitions of all variables when you send a binary data file to a third party. Thank you.
On May 13, 2021, at 2:57 PM, Fredrik Karlsson <dargosch at gmail.com> wrote: ? Hi, I am sorry but I don't understand your question, Generally, "clicking" is not something you can assume to be implemented for anything in R. However, if you read the manual for the package https://gdemin.github.io/expss/ you get an example at the bottom where an illustration of how the package can be used to create Excel tables which would then be easy to interact with through clicking. Is that what you wanted? Fredrik
On Thu, May 13, 2021 at 4:49 AM Steven Yen <styen at 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.
mydata<-read_excel("data/Excel/hseinv.xlsx",na=".")
library(expss)
mydata=apply_labels(mydata,
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)",
lprice_1="lprice[_n-1]",
linvpc_1="linvpc[_n-1]",
gprice ="lprice - lprice_1",
ginvpc ="linvpc - linvpc_1")
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
-- "Life is like a trumpet - if you don't put anything into it, you don't get anything out of it."
Hi.
Maybe you could use attributes.
dput(vec.m)
structure(list(Group.1 = c(2003, 2021, 2003, 2021, 2003, 2021,
2003, 2021, 2003, 2021, 2003, 2021, 2003, 2021, 2003, 2021, 2003,
2021), variable = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L,
5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L), .Label = c("s6", "s5",
"s4", "s3", "s2", "s1.5", "s.7", "s.5", "pod"), class = "factor"),
value = c(3.29, 0.525, 5.01, 1.385, 16.38, 7.67, 5.535, 3.28,
25.49, 24.41, 10.285, 12.79, 8.905, 12.92, 1.68, 3.67, 2.595,
5.06)), row.names = c(NA, -18L), class = "data.frame")
attr(vec.m, "some.kind.of.value") <- c("some specialvector", "another special vector", "just ordinary vector")
You can access them by attributes or attr. attributes(vec.m) $row.names [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 $names [1] "Group.1" "variable" "value" $class [1] "data.frame" $some.kind.of.value [1] "some specialvector" "another special vector" "just ordinary vector"
attr(vec.m, "some")
[1] "some specialvector" "another special vector" "just ordinary vector"
Cheers Petr
-----Original Message----- From: R-help <r-help-bounces at r-project.org> On Behalf Of Steven Yen Sent: Thursday, May 13, 2021 10:07 AM To: Fredrik Karlsson <dargosch at gmail.com> Cc: R-help Mailing List <r-help at r-project.org> Subject: Re: [R] Variable labels Thanks. What I need ?appears? simple. The .RData file is provided by a third party (likely converted from a different data format such as SAS in which variable labels (not value labels) are common). When I load the binary file, in the ?environment? I see, as expected, a data frame showing how many observations for how many variables. In addition, there is also an item (in the environment) (say ?desc?) containing a list of variable labels (definitions). I simply like to know how to get ?desc? in the environment?-it is a convenient way to show definitions of all variables when you send a binary data file to a third party. Thank you.
On May 13, 2021, at 2:57 PM, Fredrik Karlsson <dargosch at gmail.com>
wrote:
Hi, I am sorry but I don't understand your question, Generally, "clicking" is not
something you can assume to be implemented for anything in R.
However, if you read the manual for the package https://gdemin.github.io/expss/ you get an example at the bottom where an illustration of how the package
can be used to create Excel tables which would then be easy to interact with through clicking.
Is that what you wanted? Fredrik
On Thu, May 13, 2021 at 4:49 AM Steven Yen <styen at 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.
mydata<-read_excel("data/Excel/hseinv.xlsx",na=".")
library(expss)
mydata=apply_labels(mydata,
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)",
lprice_1="lprice[_n-1]",
linvpc_1="linvpc[_n-1]",
gprice ="lprice - lprice_1",
ginvpc ="linvpc - linvpc_1")
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
-- "Life is like a trumpet - if you don't put anything into it, you don't get
anything out of it." [[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code.
2 days later
Hi Steven, 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 a variable. 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 desc(mydata$invpc) 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. https://play.google.com/store/apps/details?id=io.robertknight.MPGL
On Wed, May 12, 2021 at 9:49 PM Steven Yen <styen at 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.
mydata<-read_excel("data/Excel/hseinv.xlsx",na=".")
library(expss)
mydata=apply_labels(mydata,
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)",
lprice_1="lprice[_n-1]",
linvpc_1="linvpc[_n-1]",
gprice ="lprice - lprice_1",
ginvpc ="linvpc - linvpc_1")
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Actually, I just found exactly what you want. Before that though, I am
having a hard time finding any such cool job despite having even had
classes with some great professors in economics at UND, and so I work in a
completely non data related thing.
Here is exactly what you want, code included. Then on the right side of
Rstudio you can click the word "desc" and get a table of the variable name
and it's description.
variable <- c("year", "inv", "pop", "price", "linv", "lpop", "lprice", "t",
"invpc", "linvpc", "lprice_1", "linvpc_1", "gprice", "ginvpc")
description <- c("1947-1988","real housing inv, millions $","population,
1000s","housing price index; 1982 = 1",
"log(inv)","log(pop)","log(price)","time trend: t=1,...,42","per
capita inv: inv/pop",
"log(invpc)","lprice[_n-1]","linvpc[_n-1]","lprice -
lprice_1","linvpc - linvpc_1")
desc <- cbind(variable, description)
Robert D. Knight, MBA
Developer of Meal Plan and Grocery List maker for Android and iOS.
https://play.google.com/store/apps/details?id=io.robertknight.MPGL
On Wed, May 12, 2021 at 9:49 PM Steven Yen <styen at 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.
mydata<-read_excel("data/Excel/hseinv.xlsx",na=".")
library(expss)
mydata=apply_labels(mydata,
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)",
lprice_1="lprice[_n-1]",
linvpc_1="linvpc[_n-1]",
gprice ="lprice - lprice_1",
ginvpc ="linvpc - linvpc_1")
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Thanks.
On 2021/5/16 ?? 11:52, Robert Knight wrote:
Hi Steven, 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 a variable. 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 desc(mydata$invpc) 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. https://play.google.com/store/apps/details?id=io.robertknight.MPGL <https://play.google.com/store/apps/details?id=io.robertknight.MPGL> On Wed, May 12, 2021 at 9:49 PM Steven Yen <styen at ntu.edu.tw <mailto:styen at 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. mydata<-read_excel("data/Excel/hseinv.xlsx",na=".") library(expss) mydata=apply_labels(mydata, ???????????????????? 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)", ???????????????????? lprice_1="lprice[_n-1]", ???????????????????? linvpc_1="linvpc[_n-1]", ???????????????????? gprice? ="lprice - lprice_1", ???????????????????? ginvpc? ="linvpc - linvpc_1")
______________________________________________
R-help at r-project.org <mailto:R-help at r-project.org> mailing list --
To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
<https://stat.ethz.ch/mailman/listinfo/r-help>
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
<http://www.R-project.org/posting-guide.html>
and provide commented, minimal, self-contained, reproducible code.