Last data update: 2014.03.03

R: Extract the Label for a Variable
LabelR Documentation

Extract the Label for a Variable

Description

Extracts the label for a variable from one or more of the *Labels files. This is useful for plots and other displays because the variable names are often cryptically short.

Usage

Label(var, labels = rbind(Lahman::battingLabels, 
                          Lahman::pitchingLabels, 
                          Lahman::fieldingLabels))

Arguments

var

name of a variable

labels

label table(s) to search, a 2-column dataframe containing variable names and labels.

Value

Returns the variable label, or var if no label is found

Author(s)

Michael Friendly

See Also

battingLabels, pitchingLabels, fieldingLabels

Examples

require(plyr)
# find and plot maximum number of homers per year
batHR <- ddply(subset(Batting, !is.na(HR)), .(yearID),
		summarise, max=max(HR))
		
with(batHR, {
  plot(yearID, max, 
       xlab=Label("yearID"), ylab=paste("Maximum", Label("HR")), 
       cex=0.8)
  lines(lowess(yearID, max), col="blue", lwd=2)
  abline(lm(max ~ yearID), col="red", lwd=2)
	})

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(Lahman)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Lahman/Label.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Label
> ### Title: Extract the Label for a Variable
> ### Aliases: Label
> ### Keywords: manip
> 
> ### ** Examples
> 
> require(plyr)
Loading required package: plyr
> # find and plot maximum number of homers per year
> batHR <- ddply(subset(Batting, !is.na(HR)), .(yearID),
+ 		summarise, max=max(HR))
> 		
> with(batHR, {
+   plot(yearID, max, 
+        xlab=Label("yearID"), ylab=paste("Maximum", Label("HR")), 
+        cex=0.8)
+   lines(lowess(yearID, max), col="blue", lwd=2)
+   abline(lm(max ~ yearID), col="red", lwd=2)
+ 	})
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>