Select_helper {metan}R Documentation

Select helper

Description

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

Usage

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


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())



[Package metan version 1.18.0 Index]