Keep every nth element in a vector, and replace the rest with a value such as ""
.
Arguments
- x
A vector.
- ...
If numeric, other arguments passed to the
scales::comma
function.- keep_nth
The increment of elements to keep as is. Defaults to
2
.- offset
An offset to start at the intended offset. Defaults to
0
. Possible replaces are-1
to (keep_nth - 2
)- replacement
The replacement value to replace non-kept elements with. Defaults to
""
.
Examples
replace_seq(seq(1000, 7000, 1000))
#> [1] "1,000" "" "3,000" "" "5,000" "" "7,000"
replace_seq(seq(1000, 7000, 1000), offset = -1)
#> [1] "" "2,000" "" "4,000" "" "6,000" ""
replace_seq(seq(1000, 7000, 1000), keep_nth = 3)
#> [1] "1,000" "" "" "4,000" "" "" "7,000"
replace_seq(LETTERS[1:12])
#> [1] "A" "" "C" "" "E" "" "G" "" "I" "" "K" ""