Very interesting! Thanks! On Wed, 12 Jul, 2023, 7:58 pm Viechtbauer, Wolfgang (NP), < wolfgang.viechtba...@maastrichtuniversity.nl> wrote:
> For value labels, factor() provides the necessary machinery. For variable > labels, one could make use of comment() (something that not too many people > seem to know about). To illustrate: > > # look at the mtcars dataset > mtcars > > # turn 'am' into a factor and use labels for the two possible levels > thereof > mtcars$am <- factor(mtcars$am, levels=c(0,1), > labels=c("automatic","manual")) > mtcars > > # add a variable label via comment() > comment(mtcars$am) <- "Type of transmission" > > # extract all the variable labels > sapply(mtcars, comment) > > Best, > Wolfgang > > >-----Original Message----- > >From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Anupam > Tyagi > >Sent: Wednesday, 12 July, 2023 14:11 > >To: Martin Maechler > >Cc: r-help mailing list > >Subject: Re: [R] Variable and value labels > > > >Thanks. Sorry, I have not consulted help pages, but did a web search. Web > >search results are referring to some package or the other for doing > labels. > >Thanks for letting me know that this can be done in base-R. I will try to > >find the relevant information in R documentation. > > > >On Wed, 12 Jul, 2023, 1:33 pm Martin Maechler, < > maech...@stat.math.ethz.ch> > >wrote: > > > >> >>>>> Anupam Tyagi > >> >>>>> on Wed, 12 Jul 2023 09:18:55 +0530 writes: > >> > >> > Hello, > >> > >> > is there an easy way to do variable and value labels (for > >> > factor variables) in base-R, without using a package. > >> > >> Yes, there are many. > >> How many help pages (in R , i.e. base-R) did you consult? > >> > >> Very general questions as the above are not very useful, > >> because typically the only concised answer can be yes/no. > >> > >> > >> > If not, what is an easy and good way to do labels, using an > >> > add-on package. > >> > >> > >> > -- > >> > Anupam. > [[alternative HTML version deleted]] ______________________________________________ R-help@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.