var_lab: Set or get variable label

View source: R/labels.R

var_labR Documentation

Set or get variable label

Description

These functions set/get/drop variable labels. For value labels see val_lab.

  • var_lab returns variable label or NULL if label doesn't exist.

  • var_lab<- set variable label.

  • drop_lab drops variable label.

  • has.label check if variable label exists.

Usage

var_lab(x)

## S3 method for class 'data.frame'
var_lab(x)

var_lab(x) <- value

has.label(x)

drop_lab(x)

Arguments

x

Variable. In the most cases it is numeric vector.

value

A character scalar - label for the variable x.

Details

Variable label is stored in attribute "label" (attr(x,"label")). To drop variable label use var_lab(var) <- NULL or drop_lab(var).

Value

var_lab return variable label. If label doesn't exist it return NULL . var_lab<- return variable (vector x) with attribute "label" which equals submitted value.

References

This is a modified version from 'expss' package.

Examples

data(mtcars)
mtcars = within(mtcars,{
                var_lab(mpg) = "Miles/(US) gallon"
                var_lab(cyl) = "Number of cylinders"
                var_lab(disp) = "Displacement (cu.in.)"
                var_lab(hp) = "Gross horsepower"
                var_lab(drat) = "Rear axle ratio"
                var_lab(wt) = "Weight (lb/1000)"
                var_lab(qsec) = "1/4 mile time"
                var_lab(vs) = "V/S"
                val_lab(vs) = c("V-shaped" = 0, "straight"=1)
                var_lab(am) = "Transmission"
                val_lab(am) = c(automatic = 0, manual=1)
                var_lab(gear) = "Number of forward gears"
                var_lab(carb) = "Number of carburetors"
})

table(mtcars$am)



shug0131/cctu documentation built on Nov. 10, 2023, 12:03 p.m.