
NA
in a character vector with a given string.stri_replace_na(str, replacement = "NA")
str2 <- stri_enc_toutf8(str);
str2[is.na(str2)] <- stri_enc_toutf8(replacement);
str2
.
It may be used e.g. wherever ``plain R'' NA
handling is
desired, see Examples.stri_replace
,
stri_replace_all
,
stri_replace_all_charclass
,
stri_replace_all_coll
,
stri_replace_all_fixed
,
stri_replace_all_regex
,
stri_replace_first
,
stri_replace_first_charclass
,
stri_replace_first_coll
,
stri_replace_first_fixed
,
stri_replace_first_regex
,
stri_replace_last
,
stri_replace_last_charclass
,
stri_replace_last_coll
,
stri_replace_last_fixed
,
stri_replace_last_regex
;
stri_trim
, stri_trim
,
stri_trim_both
,
stri_trim_left
,
stri_trim_right
;
stringi-search
x <- c('test', NA)
stri_paste(x, 1:2) # "test1" NA
paste(x, 1:2) # "test 1" "NA 2"
stri_paste(stri_replace_na(x), 1:2, sep=' ') # "test 1" "NA 2"
Run the code above in your browser using DataLab