label: Manipulate labels (or factors)

Description Usage Arguments Details Author(s) See Also Examples

View source: R/label.R

Description

label assigns value labels to variables

Usage

1

Arguments

x

A vector

labels

specify a character vector that correspond to the levels

Details

See the following details on assigning labels on different types of vector.

Numeric or factor The order of the labels appearing is the same as output from tab function.

Character For character, the order of labels have to be specified by alphabetical order.

Logical TRUE means 1 and FALSE 2 in a logical vector. Hence, levels shoud be corresponding to the numeric representation of the vector.

Author(s)

Myo Minn Oo (Email: dr.myominnoo@gmail.com | Website: https://myominnoo.github.io/)

See Also

gen, egen

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
str(infert)

## Example 1: Numeric vector
table(infert$case)
case <- label(infert$case, c("No", "Yes"))
table(case)

## Example 2: factor
table(infert$education)
edu <- label(infert$education, c("low", "middle", "high"))
table(edu)

## Example 3: character
sex <- rep(c("Male", "Female", NA), c(30, 60, 10))
sex; table(sex)
sex1 <- label(sex, c('f', 'm'))
sex1; table(sex1)
label(sex, c('f', 'm', 'missing'))

## Example 4: Logical
s <- sex == "Male"
s; table(s)
s1 <- label(s, c("male", "female"))
s1; table(s1)
label(s, c('male', 'female', 'missing'))

myominnoo/stats2 documentation built on Nov. 4, 2019, 8:33 p.m.