r-formula

Use of Tilde (~) and period (.) in R

独自空忆成欢 提交于 2021-01-18 07:12:48
问题 I'm going over looping with tidyverse and purrr using Hadley's R4DS book and am a little confused as to the exact usage of the tilde ~ symbol and period symbol. So when writing for loops, or using map(), instead of writing out function(), it appears you can use the tilde symbol instead ~. Does this only apply to for loops? so as below... models <- mtcars %>% split(.$cyl) %>% map(~lm(mpg ~ wt, data = .)) Additionally, the period i was told can be used "to refer to the current list element" .

Use of Tilde (~) and period (.) in R

随声附和 提交于 2021-01-18 07:10:55
问题 I'm going over looping with tidyverse and purrr using Hadley's R4DS book and am a little confused as to the exact usage of the tilde ~ symbol and period symbol. So when writing for loops, or using map(), instead of writing out function(), it appears you can use the tilde symbol instead ~. Does this only apply to for loops? so as below... models <- mtcars %>% split(.$cyl) %>% map(~lm(mpg ~ wt, data = .)) Additionally, the period i was told can be used "to refer to the current list element" .

Use of Tilde (~) and period (.) in R

為{幸葍}努か 提交于 2021-01-18 07:09:56
问题 I'm going over looping with tidyverse and purrr using Hadley's R4DS book and am a little confused as to the exact usage of the tilde ~ symbol and period symbol. So when writing for loops, or using map(), instead of writing out function(), it appears you can use the tilde symbol instead ~. Does this only apply to for loops? so as below... models <- mtcars %>% split(.$cyl) %>% map(~lm(mpg ~ wt, data = .)) Additionally, the period i was told can be used "to refer to the current list element" .