stri_replace_na {stringi} | R Documentation

## Replace Missing Values in a Character Vector

### Description

This function offers a convenient way to replace each `NA` in a character vector with a given string.

### Usage

    stri_replace_na(str, replacement = "NA")

### Arguments

`str` | character vector or an object coercible to
`replacement` | single string

### Details

This function is roughly equivalent to `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.

### Value

Returns a character vector.

### See Also

Other search_replace: `stri_replace_all`, `stri_trim_both`, `stringi-search`

### Examples

    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"

[Package stringi version 1.1.5 Index]