add_group_col: Add a new variable based on some condition and group rows...

Description Usage Arguments Examples

Description

Add a new variable based on some condition and group rows based on the new variable

Usage

1
add_group_col(data, name, where, value, add = TRUE)

Arguments

data

a data frame

name

the name of the new variable to be created

where

the condition in which the new variable should have a value (NA otherwise)

value

an expression for the content of the new variable when the condition is true

add

when 'add = TRUE' (default), the new variable will add to existing groups. Set to 'FALSE' to override all existing groups (passed to 'dplyr::group_by')

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
lexicon_str <-
'\\lx bureau
\\sn 1
\\de desk
\\sn 2
\\de office

\\lx langue
\\sn 1
\\de language
\\sn 2
\\de tongue
'

read_lexicon(file = lexicon_str, regex = "\\\\?([a-z]*)\\s?(.*)", into = c("code", "value")) %>%
    add_group_col(name = lx_group, where = code == "lx", value = paste0(line, ": ", value)) %>%
    add_group_col(name = sense_no, where = code == "sn", value = value)

CoEDL/tidylex documentation built on May 7, 2019, 10:50 p.m.