Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用mutate_控制dplyr评估范围__R_Dplyr - Fatal编程技术网

使用mutate_控制dplyr评估范围_

使用mutate_控制dplyr评估范围_,r,dplyr,R,Dplyr,是否有办法确保每个(或者可能是函数)在父帧中查找函数?考虑: library(dplyr) # 0.4.1 library(magrittr) # 1.5 fun_list <- list(a=quote(rev), b=quote(sort)) iris[1:5, 1:2] %>% mutate_each_(funs_(fun_list), c("Sepal.Length")) 但是: 一个简单的变异有效: iris[1:5, 1:2] %>% mutate(a=m

是否有办法确保每个(或者可能是函数)在父帧中查找函数?考虑:

library(dplyr)    # 0.4.1
library(magrittr) # 1.5

fun_list <- list(a=quote(rev), b=quote(sort))
iris[1:5, 1:2] %>% mutate_each_(funs_(fun_list), c("Sepal.Length"))
但是:

一个简单的
变异
有效:

iris[1:5, 1:2] %>% mutate(a=my_rev(Sepal.Length), b=my_srt(Sepal.Length))

您应该在此处使用公式
~
符号,而不是
quote()

my_rev
my_rev <- rev
my_srt <- sort
fun_list2 <- list(a=quote(my_rev), b=quote(my_srt))
iris[1:5, 1:2] %>% mutate_each_(funs_(fun_list2), c("Sepal.Length"))
Error in mutate_impl(.data, dots) : could not find function "my_rev"
iris[1:5, 1:2] %>% mutate(a=my_rev(Sepal.Length), b=my_srt(Sepal.Length))
my_rev <- rev
my_srt <- sort
fun_list2 <- list(a = ~my_rev, b = ~my_srt)
iris[1:5, 1:2] %>% mutate_each_(funs_(fun_list2), c("Sepal.Length"))