[R] Simple question on a function

2006-10-02 Thread Serguei Kaniovski
I would like to apply the following function to the rows of the matrix mat, so that freq[1],...,freq[4] are the four elements of each row. min_chi2-function(freq){ obj-function(x){ (freq[1]-(1-x[1])*(1-x[2])-x[3]*sqrt(x[1]*(1-x[1])*x[2]*(1-x[2])))^2/freq[1]+

Re: [R] Simple question on a function

2006-10-02 Thread Christoph Buser
Dear Serguei There might be more efficient ways, but this should work: ## Define function that you want to optimize. In your case I ## copied your code, but included freq as a second argument: fun - function(x, freq) {