Re: [R] Stop R from changing matrix to numeric

2014-12-17 Thread Jeff Newmiller
as.matrix(c(1,1)) gives a matrix with only one column, but your function assumes you have at least two columns (you refer to x[,2]). Please make your examples reproducible (run it yourself in a fresh instance of R) to obtain best results with questions on this list. However, you might just be

Re: [R] Stop R from changing matrix to numeric

2014-12-17 Thread Peter Alspach
-project.org Subject: [R] Stop R from changing matrix to numeric I have the following cost function: cost-function(x){ x[,1]*sin(4*x[,1])+1.1*x[,2]*sin(2*x[,2]) } If I send in a matrix which has MORE than one row and 2 columns, this works fine. However, if I try to do cost(t(as.matrix(c(1,1

[R] Stop R from changing matrix to numeric

2014-12-16 Thread Sachinthaka Abeywardana
I have the following cost function: cost-function(x){ x[,1]*sin(4*x[,1])+1.1*x[,2]*sin(2*x[,2]) } If I send in a matrix which has MORE than one row and 2 columns, this works fine. However, if I try to do cost(t(as.matrix(c(1,1 it gives me an index error. When I tried debugging it, I found

Re: [R] Stop R from changing matrix to numeric

2014-12-16 Thread PIKAL Petr
, December 17, 2014 7:55 AM To: r-help@r-project.org Subject: [R] Stop R from changing matrix to numeric I have the following cost function: cost-function(x){ x[,1]*sin(4*x[,1])+1.1*x[,2]*sin(2*x[,2]) } If I send in a matrix which has MORE than one row and 2 columns, this works fine