eda_trim: Trims vector and dataframe objects

View source: R/trim.R

eda_trimR Documentation

Trims vector and dataframe objects

Description

Removes records from either tail-ends of a sorted dataset. Trimming can be performed by number of records (specify the num = option) or by quantiles (specify the prop= option).

eda_trim Trims a vector
eda_trim_df Trims a data frame
eda_ltrim Left-trims a vector
eda_rtrim Right-trims a vector
eda_ltrim_df Left-trims a dataframe
eda_rtrim_df Right-trims a dataframe

Usage

eda_trim(x, prop = 0.05, num = 0)

eda_trim_df(dat, x, prop = 0.05, num = 0)

eda_ltrim(x, prop = 0.05, num = 0)

eda_ltrim_df(dat, x, prop = 0.05, num = 0)

eda_rtrim(x, prop = 0.05, num = 0)

eda_rtrim_df(dat, x, prop = 0.05, num = 0)

Arguments

x

Vector of values (if trimming a vector) or the column whose values are used to trim a dataframe (applies to *_df functions only)

prop

Fraction of values to trim

num

Number of values to trim

dat

Dataframe (applies to *_df functions only)

Details

  • The input dataset does not need to be sorted (sorting is performed in the functions).

  • If num is set to zero, then the function will assume that the trimming is to be done by fraction (defined by the prop parameter).

  • If eda_trim or eda_trim_df functions are called, the num and prop values apply to each tail. For example, if num = 5 then the 5 smallest AND 5 largest values are removed from the data.

  • NA values must be stripped from the input vector or column elements before running the trim functions.

  • Elements are returned sorted on the trimmed elements.

Value

Returns the same data type as the input (i.e. vector or dataframe)

Examples


# Trim a vector by 10% (i.e. 10% of the smallest and 10% of the largest
# values)
eda_trim( mtcars[,1], prop=0.1)

# Trim a data frame by 10% using the mpg column(i.e. 10% of the smallest
# and 10% of the largest mpg values)
eda_trim_df( mtcars, mpg, prop=0.1)

mgimond/tukeyedar documentation built on March 19, 2024, 8:44 a.m.