Learn R Programming

yamlet (version 0.5.3)

codelist.data.frame: Create a Codelist for Data Frame

Description

Creates a codelist for data.frame. Assuming one-to-one correspondence of names and values (error otherwise), returns a named list of unique values, in order given by as.factor(names).

Usage

# S3 method for data.frame
codelist(x, names, values, ...)

Arguments

x

data.frame

names

unquoted column name supplying list names

values

unquoted colum name supplying list values

...

ignored arguments

Value

see methods

See Also

Other codelist: codelist()

Examples

Run this code
# NOT RUN {
library(magrittr)

# Suppose we have a numeric and a character version of treatment:

x <- data.frame(
  TRTN =  c(        0,      1,            2,         0),
  TRTC =  c('placebo', 'drug', 'comparitor', 'placebo')
)

x

# Further, we wish to specify a particular display order:

x$TRTC <- factor(x$TRTC, levels = c('drug', 'comparitor', 'placebo'))

# We can use TRTC as the guide for TRTN:

x %<>% modify(TRTN, guide = codelist(x, TRTC, TRTN))

x %>% decorations(TRTN)


# }

Run the code above in your browser using DataLab