【发布时间】:2015-07-06 15:44:47
【问题描述】:
set.seed(8)
data <-
data.frame(A=rnorm(10),
B=rnorm(10))
fun <- function(df,x,y){
require(dplyr)
res <-
filter(df,A<x,B>y) %>%
nrow()
return(res)
}
这适用于 x 和 y 的单个值:
fun(x=1,y=0,df=data)
我想使用 outer() (或类似的)来组合 x 和 y 但不知道如何传递 df 参数。这似乎与此处的问题相同:
Using outer() with a multivariable function。
但是通过... 传递df 不起作用:
outer(x=c(0,2),y=c(0,2),fun,df=data)
缺少什么?
【问题讨论】:
-
fun的前两个参数必须是您的x和y并且如果您想使用 @987654329,则必须针对这些参数进行矢量化@. -
@Roland:你能否详细说明...'必须矢量化'
-
矢量化(yourFucntion...., vec=c("x", "y"))
-
@Legalizelt:我没明白对不起
标签: r combinations dplyr