Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

op-na-default

Replace missing values


Description

This infix function is similar to %||% but is vectorised and provides a default value for missing elements. It is faster than using base::ifelse() and does not perform type conversions.

Usage

x %|% y

Arguments

x

The original values.

y

The replacement values. Must be of length 1 or the same length as x.

See Also

Examples

c("a", "b", NA, "c") %|% "default"
c(1L, NA, 3L, NA, NA) %|% (6L:10L)

rlang

Functions for Base Types and Core R and 'Tidyverse' Features

v0.4.11
MIT + file LICENSE
Authors
Lionel Henry [aut, cre], Hadley Wickham [aut], mikefc [cph] (Hash implementation based on Mike's xxhashlite), Yann Collet [cph] (Author of the embedded xxHash library), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.