R 变异每个非标准评估
在我的函数中加入dplyr函数真的很困难。我理解标准评估版本的R 变异每个非标准评估,r,dplyr,R,Dplyr,在我的函数中加入dplyr函数真的很困难。我理解标准评估版本的函数后缀,但仍然存在问题,似乎尝试了eval粘贴和惰性的所有组合 尝试将多个列除以组的控件的中间值。示例数据包括iris中名为“控制”的附加列,因此每个物种有40个“正常”,10个“控制” data(iris) control <- rep(c(rep("normal", 40), rep("control", 10)), 3) iris$Control <- control 使用funs\uuu而不是funs我得到错误
函数
后缀,但仍然存在问题,似乎尝试了eval
粘贴
和惰性
的所有组合
尝试将多个列除以组的控件的中间值。示例数据包括iris中名为“控制”的附加列,因此每个物种有40个“正常”,10个“控制”
data(iris)
control <- rep(c(rep("normal", 40), rep("control", 10)), 3)
iris$Control <- control
使用
funs\uuu
而不是funs
我得到错误:…:需要数字数据如果您还没有,它可能会帮助您阅读标准评估的小插曲,尽管听起来其中一些可能很快就会改变
您的函数在mutate\u each_uu
行中缺少使用包lazyeval中的interp
。由于您正试图在funs
中使用变量名(Control
变量),因此在这种情况下,您需要funs\uu
以及interp
。请注意,在这种情况下,您根本不需要对每个对象进行变异。如果在选择要变异的列时尝试使用列名而不是列号,则需要它
以下是函数中的行的外观,而不是现有的:
mutate_each(funs_(interp(~./median(.[x == control_val]), x = as.name(control_col))),
num_cols)
norm_iris <- function(df, control_col, control_val, species, num_cols = 1:4){
out <- df %>%
group_by_(species) %>%
mutate_each_(funs(./median(.[control_col == control])), num_cols)
return(out)
}
norm_iris(iris, control_col = "Control", control_val = "control", species = "Species")
Error in UseMethod("as.lazy_dots") :
no applicable method for 'as.lazy_dots' applied to an object of class "c('integer', 'numeric')"
mutate_each(funs_(interp(~./median(.[x == control_val]), x = as.name(control_col))),
num_cols)