Reputation: 9018
when I call sapply with plink I get this error
argument is missing, with no default
any ideas to get it to work?
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]))
Upvotes: 0
Views: 25
Reputation: 206546
The big problem is that you're not passing post
to your plink
function as the first parameter. Also it's not a good idea to use =
to create variables inside the with()
function since those are interpreted as named parameters. This should work
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]))
Upvotes: 2