If the number of unique numbers is five or fewer, then they will simply be converted to factors in order, otherwise, they will be passed to cut and pretty, preserving the lowest value.

fac_from_num(x)

Arguments

x

a vector of integers or numerics

Value

a factor

Examples

fac_from_num(1:100)
#>   [1] [0,20]   [0,20]   [0,20]   [0,20]   [0,20]   [0,20]   [0,20]   [0,20]  
#>   [9] [0,20]   [0,20]   [0,20]   [0,20]   [0,20]   [0,20]   [0,20]   [0,20]  
#>  [17] [0,20]   [0,20]   [0,20]   [0,20]   (20,40]  (20,40]  (20,40]  (20,40] 
#>  [25] (20,40]  (20,40]  (20,40]  (20,40]  (20,40]  (20,40]  (20,40]  (20,40] 
#>  [33] (20,40]  (20,40]  (20,40]  (20,40]  (20,40]  (20,40]  (20,40]  (20,40] 
#>  [41] (40,60]  (40,60]  (40,60]  (40,60]  (40,60]  (40,60]  (40,60]  (40,60] 
#>  [49] (40,60]  (40,60]  (40,60]  (40,60]  (40,60]  (40,60]  (40,60]  (40,60] 
#>  [57] (40,60]  (40,60]  (40,60]  (40,60]  (60,80]  (60,80]  (60,80]  (60,80] 
#>  [65] (60,80]  (60,80]  (60,80]  (60,80]  (60,80]  (60,80]  (60,80]  (60,80] 
#>  [73] (60,80]  (60,80]  (60,80]  (60,80]  (60,80]  (60,80]  (60,80]  (60,80] 
#>  [81] (80,100] (80,100] (80,100] (80,100] (80,100] (80,100] (80,100] (80,100]
#>  [89] (80,100] (80,100] (80,100] (80,100] (80,100] (80,100] (80,100] (80,100]
#>  [97] (80,100] (80,100] (80,100] (80,100]
#> Levels: [0,20] (20,40] (40,60] (60,80] (80,100]
fac_from_num(sample(100, 5))
#> [1] 72 40 15 5  6 
#> Levels: 5 6 15 40 72