Q: pass parameters(data frame) in contrOptim in R ui = rbind(c(1,1,1,1,1,1), c(-1,-1,-1,-1,-1,-1))
ci = c(0.999, -1.001)
init = c(1,0,0,0,0,0)

parameters <- constrOptim(theta=init,optimize_ranks,grad=NULL,data,ui = ui,hessian=FALSE,method=if(is.null(grad))"Nelder-Mead" else "BFGS",ci = ci,init=init)

optimize_ranks <- function(data,init)
{
 data$variance <- init[1]*((data$vs.rank - data$mew)^2) + init[2]*((data$gbu.rank - data$mew)^2) + init[3]*((data$vr.rank - data$mew)^2) + init[4]*((data$vre.rank - data$mew)^2) + init[5]*((data$vss.rank - data$mew)^2) + init[6]*((data$gbs.rank - data$mew)^2)
 weighted_variance <- sum(data$variance)

 #print(weighted_variance)

 return(weighted_variance)
}

The data frame data has all these columns, for sure. I am getting this error on this :
Error in data$vs.rank : $ operator is invalid for atomic vectors

