当我用plink调用sapply时出现此错误
缺少参数,没有默认值
任何让它发挥作用的想法?
plink = function(post, original_predictor1,original_predictor2){
with(post,
result = parameter_vector1*original_predictor1 + parameter_vector2*original_predictor2
)
return(result)
}
post = data.frame(parameter_vector1 = c(1,2),parameter_vector2 = c(9,5))
original_predictor1 = c(1,2) #original predictor variable x in y = beata*x
original_predictor2 = c(10,20) #original predictor variable x in y = beata*x
pred.raw = sapply(1:2, function(i) plink(original_predictor1[i],original_predictor2[i]))
答案 0 :(得分:2)
最大的问题是您没有将post
作为第一个参数传递给plink
函数。使用=
在with()
函数内创建变量也不是一个好主意,因为它们被解释为命名参数。这应该工作
plink = function(post, original_predictor1, original_predictor2){
result <- with(post, parameter_vector1*original_predictor1 + parameter_vector2*original_predictor2
)
return(result)
}
post = data.frame(parameter_vector1 = c(1,2),parameter_vector2 = c(9,5))
original_predictor1 = c(1,2) #original predictor variable x in y = beata*x
original_predictor2 = c(10,20) #original predictor variable x in y = beata*x
pred.raw = sapply(1:2, function(i) plink(post, original_predictor1[i],original_predictor2[i]))