prune: Prune a numeric vector

Description Usage Arguments Details Value Examples

Description

prune returns a pruned numeric vector.

Usage

1
2
prune(x, method = c("value", "percentile"), low = NULL, high = NULL,
  replace = NULL)

Arguments

x

A numeric vector.

method

A character string indicating the desired method of pruning with "value" being the default. This must be (an abbreviation of) one of the strings "value" or "percentile". See Details for more information.

low

The lower value/percentile for pruning See Details for more information.

high

The upper value/percentile for pruning See Details for more information.

replace

Either NULL ("rounds" values according to the low and high arguments), NA, or a single value that will replace the pruned values. The default is NULL.

Details

prune returns a pruned version of the numeric vector x. NA values in x are ignored during the pruning process but are preserved in the output. prune will do one-sided pruning if only one low or high argument is provided (e.g. prune(x, low=-1) will prune x at a lower value of -1).

prune is designed to be readable from the function call. For example:

The arguments low and high are used based on method. prune offers several different options for method:

Value

The output of prune is a pruned numeric vector with the same length as x.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
set.seed(51)
x <- rnorm(1e4)
summary(x)

# pruning at the values -1 and 1!
x_val <- prune(x, low=-1, high=1)
summary(x_val)

# pruning at 5th and 95th percentiles!
x_per <- prune(x, "percentile", low=.05, high=.95)
summary(x_per)

# pruning values above the 95th percentile!
x_hi <- prune(x, "percentile", high=.95)
summary(x_hi)

# pruning values converted to NAs!
x_NA <- prune(x, "percentile", low=.05, high=.95, replace=NA)
summary(x_NA)

danielmarcelino/SciencesPo documentation built on Oct. 20, 2019, 1:15 a.m.