What does the first tilde mean in purrr :: map

I looked at this example that uses map. There he is:

mtcars %>%
  split(.$cyl) %>% # from base R
  map(~ lm(mpg ~ wt, data = .))

What is the meaning of the first tilde in map(~ lm...? That is, how does R interpret the first tilde? (I understand that the second tilde points to a function ...). Another way to ask the question is why the following does not work?

mtcars %>%
  split(.$cyl) %>% # from base R
  map(lm(mpg ~ wt, data = .))
+4
source share
1 answer

According to the reference documentation on the map , you mapneed a function, but it also takes a formula, a character vector, a numerical vector or a list, the last of which are converted to functions.

~ R . , ~ lm(mpg ~ wt, data = .) - . R, . ,

x <- ~f(a+b)

f, a b . ~ lm(mpg ~ wt, data = .) function(x) {lm(mpg ~ wt, data = x)}, map . .

lm(mpg ~ wt, data = .) R., . . , map .

+6

Source: https://habr.com/ru/post/1680448/


All Articles