0

I am trying to use the package CVXR to do my optimization. I am following the instructions from this page: https://rviews.rstudio.com/2017/11/27/introduction-to-cvxr/

My problem is a little complicated to I want to put my coefficient variables (the variables I want to optimize) into a matrix to help with coding. However, I could not do it in R

beta = Variable(n)
matrixbeta = matrix(beta,nrow=2)

Error in as.vector(data) : no method for coercing this S4 class to a vector

Really appreciate any help.

TDo
  • 686
  • 4
  • 9
  • 22
  • 1
    `beta` does not contain any data, it's the wrong sort of object to feed to `matrix`. The idea of that package is you do some optimisation, get an object `answer` and then you can put the coefficients of that answer into a `matrix`. – JDL Nov 29 '17 at 10:20

1 Answers1

1

beta is a S4 object, not a numeric value, so it cannot be placed in a matrix. What are you trying to do with the coefficient? You can create an arbitrary m by n variable with Variable(rows = m, cols = n) and use it in mathematical operations as you would a matrix.

anqif
  • 73
  • 1
  • 6