-1
$\begingroup$
f1 <- function(a,b,c,d,e,f) { 

  -111.605*a-208.39+(14.882-b)^2+35.29813*c-.001251205/d-1.050695*e+11.63420*f
}

x = matrix(c(1:66), byrow = T, ncol = 6)
f1(x)

An error of the following occurs:

Error in f1(x) : argument "b" is missing, with no default

$\endgroup$
0
$\begingroup$

This should give you the answer:

f1 <- function(a,b,c,d,e,f) { 

  -111.605*a-208.39+(14.882-b)^2+35.29813*c-.001251205/d-1.050695*e+11.63420*f
}
x = matrix(c(1:66), byrow = T, ncol = 6)

for(i in 1:nrow(x)){
  new_out[i] <- f1(x[,1][i],x[,2][i],x[,3][i],x[,4][i],x[,5][i],x[,6][i])
}

new_out <- as.data.frame(new_out)

or instead of that for loop you can use this:

new_out2 <- as.data.frame(f1(x[,1],x[,2],x[,3],x[,4],x[,5],x[,6]))
colnames(new_out2) <- "new_out"

Reason for the error is, it was taking x as 1 element. So, I called this function using its name.

Do let me know if you any issues.

$\endgroup$
  • $\begingroup$ Yes, I figured out that the newdata X must have the same column names of the functions. But thank you so much for your reply.Appreciated that. $\endgroup$ – Mithun Ghosh Nov 21 '17 at 21:23
  • $\begingroup$ welcome, not same name, same number of coulmns. $\endgroup$ – Toros91 Nov 22 '17 at 1:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.