separate_data: separate_data

Description Usage Arguments Details Value Examples

View source: R/separate_data.R

Description

Splits a dataframe in half and returns a new dataframe whose column names match a certain naming pattern.

Usage

1
separate_data(dataframe, column_regex_pattern, inverse = FALSE)

Arguments

dataframe

a dataframe.

column_regex_pattern

character string containing a regular expression that represente the column selection. If an empty chain is passed the dataframe will be returned intact.

inverse

logical. The function returns the inverse of the result if this parameter is set to true.

Details

separate_data splits a dataframe in half according to the names of the columns. This function returns a new dataframe whose column names match a certain naming pattern. Its behaviour can also be reversed. It is based on column selection using the grep function. See documentation grep function for more information about regex.

Value

returns a part of the original dataframe

Examples

1
2
3
4
5
6
7
A_column <- c(1, 2, 3)
B_column <- c(4, 5, 6)
C_column <- c(7, 8, 9)
df <- data.frame(A_column, B_column, C_column)

Bs <- separate_data(df, "^B")
notBs <- separate_data(df, "^B", inverse = TRUE)

JeremyGillard/somar documentation built on March 19, 2021, 10:50 a.m.