Create sequences of numbers like seq() or seq_len() but with zeros prefixed to keep numerical order

seq_zeros(seq_length, num_zeros = NULL)

Arguments

seq_length

a seqeunce or numbers of numbers to create sequence. Users can provide sequence (1:XX) or number of values to add in sequence (will be used as second number in seq_len; 1:XX).

num_zeros

number of zeros to prefix sequence, default is (e.g, 01, 02, 03, ...)

Value

vector of numbers in sequence

References

Base code from stackoverflow post: https://stackoverflow.com/a/38825614

Examples

# Using sequence
new_seq <- seq_zeros(seq_length = 1:15, num_zeros = 1)
new_seq
#>  [1] "01" "02" "03" "04" "05" "06" "07" "08" "09" "10" "11" "12" "13" "14" "15"

# Using number
new_seq <- seq_zeros(seq_length = 15, num_zeros = 1)
new_seq
#>  [1] "01" "02" "03" "04" "05" "06" "07" "08" "09" "10" "11" "12" "13" "14" "15"

# Sequence with 2 zeros
new_seq <- seq_zeros(seq_length = 1:15, num_zeros = 2)
new_seq
#>  [1] "001" "002" "003" "004" "005" "006" "007" "008" "009" "010" "011" "012"
#> [13] "013" "014" "015"