Summary I was reading an article on the subject of dplyr's across function. Looking at the first example of use, I saw the use of operators that I have never seen before. I do not know if they are inherently apart of dplyr or from some other package. Either way, I do not understand their use in the code.
Code Example:
starwars |>
summarize(across(where(is.character), ~ length(unique(.x))))
The result is a 1 x 8 tibble.
I understand the first argument to across, it is the second argument that perplexes me. What does ~length(unique(.x))
mean? What does the .x code mean? I understand that length is being applied to every character vector in the tibble, but what does "unique" do for the code fragment?
What have I tried to resolve this problem myself? I have tried using Google to search for [R] ~ operator and received no relevant results. I also tried rdrr.io, r-project.org, and CRAN without a resolution. As well as the tidyverse.org and the documentation for purrr--this was due to seeing someone reference purrr when using the very same syntax in their code.
Question:
Can someone help me understand what is happening internally?