Fill blank entries in a vector
fillBlanks(x, blankGrep = c("[ \t]*"), first = "", ...)
character vector
vector of grep patterns, or NA
, indicating
the type of entry to be considered blank.
Each blankGrep
pattern is searched using jamba::proigrep()
, which
by default uses case-insensitive regular expression pattern
matching.
options character string intended when the first
entry of x
is blank. By default ""
is used.
additional parameters are ignored.
Character vector where blank entries are filled with the most recent non-blank value.
This function takes a character vector and fills any blank (missing) entries with the last non-blank entry in the vector. It is intended for situations like imported Excel data, where there may be one header value representing a series of cells.
The method used does not loop through the data, and should scale fairly well with good efficiency even for extremely large vectors.
Other jam string functions:
asSize()
,
breaksByVector()
,
cPasteSU()
,
cPasteS()
,
cPasteUnique()
,
cPasteU()
,
cPaste()
,
formatInt()
,
gsubOrdered()
,
gsubs()
,
makeNames()
,
mixedOrder()
,
mixedSortDF()
,
mixedSorts()
,
mixedSort()
,
mmixedOrder()
,
nameVectorN()
,
nameVector()
,
padInteger()
,
padString()
,
pasteByRowOrdered()
,
pasteByRow()
,
sizeAsNum()
,
tcount()
,
ucfirst()
,
uniques()
x <- c("A", "", "", "", "B", "C", "", "", NA,
"D", "", "", "E", "F", "G", "", "");
data.frame(x, fillBlanks(x));
#> x fillBlanks.x.
#> 1 A A
#> 2 A
#> 3 A
#> 4 A
#> 5 B B
#> 6 C C
#> 7 C
#> 8 C
#> 9 <NA> <NA>
#> 10 D D
#> 11 D
#> 12 D
#> 13 E E
#> 14 F F
#> 15 G G
#> 16 G
#> 17 G