rminmax_df: Row-wise min-max

Description Usage Arguments Details Value Examples

View source: R/rminmax_df.R

Description

This function finds row-wise min-max values in two columns of a given dataframe.

Usage

1
rminmax_df(df, col1 = colnames(df)[1], col2 = colnames(df)[2], unique = F)

Arguments

df

data frame with at least two columns.

col1

character. must be a column of df.

col2

character. must be a column of df.

unique

if TRUE, duplicate rows are removed from the returned data frame.

Details

Given a data frame (df) and two of its columns (col1 and col2), this function re-arranges the content of these columns so that the first and second column contains the rowwise minimum and the rowwise maximum of the two columns, respectively. Factor values are sorted by their labels. If there are other columns in df, those columns remain unchanged. if unique = TRUE, the output data frame contains only unique rows.

Note: both columns must have same type of data.

Value

A data frame with the same set of columns as df.

Examples

1
2
my_df = data.frame(A=c(1,5,2,9,1), B = LETTERS[1:5], C=c(1,3,5,7,9))
# my_minmax_df = rminmax_df(my_df, col1='A', col2 = 'C')

alorchhota/spice documentation built on March 12, 2021, 12:05 a.m.