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. However, if I try to do cost(t(as.mat
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
ka Abeywardana
> Sent: Wednesday, 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
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
4 matches
Mail list logo