purrr :: map 수식에 col 이름 목록을 전달하고 싶습니다. 다음은 내 문제의 reprex입니다 : 내가 dplyr 0.7 "quosure"프로그래밍의 완전히 새로운 세계가 알고df col 이름 목록을 purrr :: map 공식에 전달하려면 어떻게합니까?
library(dplyr)
library(purrr)
#Make a toy df of w vars of 2 levels
cars <- mtcars %>%
select(mpg, cyl, carb) %>%
filter(cyl == 4 | cyl == 6,
carb == 2 | carb == 4)
#normal fn call, works fine
t.test(mpg ~ cyl, data = cars)
t.test(mpg ~ carb, data = cars)
Welch Two Sample t-test
data: mpg by cyl
t = 3.5371, df = 7.0689, p-value = 0.009356
Welch Two Sample t-test
data: mpg by carb
t = 3.5371, df = 7.0689, p-value = 0.009356
#Make list of cols
list_vars <- names(cars[,-1])
list_vars
[1] "cyl" "carb"
#Attempt map with formula fn call
map(list_vars, ~ t.test(mpg ~ .x, data = cars))
#Results in this error
Error in model.frame.default(formula = mpg ~ .x, data = cars) :
variable lengths differ (found for '.x')
, 그러나 이것은 매우 일반적인하고 그 앞선 무언가처럼 보인다. 어떤 도움을 주셔서 감사합니다.
:'지도 (list_vars ~ t.test (식 (붙여 넣기 ("MPG ~", .x를)) , data = cars))' – aosmith