View source: R/conditionalize.R
conditionalize.data.frame | R Documentation |
Conditionalizes attributes of data.frame.
Creates a conditional attribute
definition
for column
by mapping value
to
test
. Only considers records where
both test
and value
are defined,
and gives an error if there is not one-to-one mapping.
Can be used with write methods as an alternative
to hand-coding conditional metadata.
## S3 method for class 'data.frame'
conditionalize(x, column, attribute, test, value, ...)
x |
data.frame |
column |
unquoted name of column to conditionalize |
attribute |
unquoted name of attribute to create for column |
test |
unquoted name of column to test |
value |
unquoted name of column supplying attribute value |
... |
ignored arguments |
If the test column is character, individual elements should not contain both single and double quotes. For the conditional expressions, these values will be single-quoted by default, or double-quoted if they contain single quotes.
class 'decorated' 'data.frame'
Other conditionalize:
conditionalize()
library(magrittr)
library(dplyr)
library(csv)
file <- system.file(package = 'yamlet', 'extdata','phenobarb.csv')
x <- as.csv(file)
head(x,3)
# suppose we have an event label stored as a column:
x %<>% mutate(evid = ifelse(
event == 'dose',
'dose of drug administered',
'serum phenobarbital concentration'
)
)
# We can define a conditional label for 'value'
# by mapping evid to event:
x %<>% conditionalize(value, label, event, evid)
x %>% as_yamlet
x %>% write_yamlet
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.