library(tidyverse)
df <- tibble(col1 = c("A", "B", "C"), col2 = c(NA, Inf, 5))
#> # A tibble: 3 x 2
#> col1 col2
#> <chr> <dbl>
#> 1 A NA
#> 2 B Inf
#> 3 C 5
What is the role of the ~
tilde in line #3 in the code chunk below? It is my understanding from this SO answer that dplyr reserves the use of ~
for non-standard evaluation (NSE).
I've come across one article that has made any sense in the world of NSE. Here's hoping the ~
serves a different role (other than NSE) in my code chunk below.
df %>%
replace(is.na(.), 0) %>%
mutate_if(is.numeric, list(~na_if(abs(.), Inf))) %>% # line 3
replace(is.na(.), 1)
#> # A tibble: 3 x 2
#> col1 col2
#> <chr> <dbl>
#> 1 A 0
#> 2 B 1
#> 3 C 5