Select_helper: Select helper

Description Usage Arguments Examples

Description

These functions allow you to select variables based operations with prefixes and suffixes and length of names.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
difference_var(prefix, suffix)

intersect_var(prefix, suffix)

union_var(prefix, suffix)

width_of(n, vars = peek_vars(fn = "width_of"))

width_greater_than(n, vars = peek_vars(fn = "width_greater_than"))

width_less_than(n, vars = peek_vars(fn = "width_less_than"))

lower_case_only(vars = peek_vars(fn = "lower_case_only"))

upper_case_only(vars = peek_vars(fn = "upper_case_only"))

title_case_only(vars = peek_vars(fn = "title_case_only"))

Arguments

prefix

A prefix that start the variable name.

suffix

A suffix that end the variable name.

n

The length of variable names to select. For width_of() the selected variables contains n characters. For width_greater_than() and width_less_than() the selected variables contains greater and less characteres than n, respectively.

vars

A character vector of variable names. When called from inside selecting functions like select_cols() these are automatically set to the names of the table.

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
26
27
28
29
30
31
32
33
library(metan)


# Select variables that start with "C" and not end with "D".
data_ge2 %>%
select_cols(difference_var("C", "D"))

# Select variables that start with "C" and end with "D".
data_ge2 %>%
select_cols(intersect_var("C", "D"))

# Select variables that start with "C" or end with "D".
data_ge2 %>%
select_cols(union_var("C", "D"))

# Select variables with width name of 4
data_ge2 %>%
select_cols(width_of(4))

# Select variables with width name greater than 2
data_ge2 %>%
select_cols(width_greater_than(2))

# Select variables with width name less than 3
data_ge2 %>%
select_cols(width_less_than(3))

# Creating data with messy column names
df <- head(data_ge, 3)
colnames(df) <- c("Env", "gen", "Rep", "GY", "hm")
select_cols(df, lower_case_only())
select_cols(df, upper_case_only())
select_cols(df, title_case_only())

metan documentation built on Nov. 10, 2021, 9:11 a.m.