Skip to contents

generate outliers from a series of number

Usage

gen_outlier(
  x,
  n,
  digits = 0,
  side = "both",
  lim = NULL,
  assign_n = NULL,
  only_out = TRUE
)

Arguments

x

number vector

n

number of outliers to generate

digits

the digits of outliers

side

should be one of both, low, high

lim

a two-length vector to assign the limitations of the outliers if method is both, the outliers will be limited in [lim[1], low_outlier_threshold] and [high_outlier_threshold, lim[2]] ; if method is low, the outliers will be limited in [lim[1], min(low_outlier_threshold, lim[2])] ; if method is high, the outliers will be limited in [max(high_outlier_threshold, lim[1]), lim[2]]

assign_n

manually assign the number of low outliers or high outliers when method is both

only_out

only return outliers

Value

number vector of outliers

Examples

x <- seq(0, 100, 1)

gen_outlier(x, 10)
#>  [1] -177 -165  -54 -128  -84  245  177  216  194  244

# generation limits
gen_outlier(x, 10, lim = c(-80, 160))
#>  [1] -60 -57 -66 -52 -51 151 155 153 157 152

# assign the low and high outliers
gen_outlier(x, 10, lim = c(-80, 160), assign_n = c(0.1, 0.9))
#>  [1] -70 155 159 153 159 152 153 155 157 152

# just generate low outliers
gen_outlier(x, 10, side = "low")
#>  [1]  -69 -117  -83 -108 -155  -64 -164  -67 -178 -104

# return with raw vector
gen_outlier(x, 10, only_out = FALSE)
#>   [1] -176  -55 -135 -104 -181  298  225  270  219  280    0    1    2    3    4
#>  [16]    5    6    7    8    9   10   11   12   13   14   15   16   17   18   19
#>  [31]   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34
#>  [46]   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49
#>  [61]   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64
#>  [76]   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79
#>  [91]   80   81   82   83   84   85   86   87   88   89   90   91   92   93   94
#> [106]   95   96   97   98   99  100