Linear optimization using R

Linear optimization using R, in this tutorial we are going to discuss the linear optimization problems in R.

Optimization is everything nowadays. We all have finite resources and time and we want to make the maximum profit out of that.

Companies want to makes maximum profits based on limited resources they have, yes optimization is the solution for that.

Data scientists can provide optimal solutions based on given constraints to achieve maximum profit.

Significance of Spearman’s Rank correlation


To find the optimal solution for the problem given below.

Suppose a company wants to maximize the profit for two products A and B which are sold at $25 and $20 respectively.

There are 1800 resource units available every day and product A requires 20 units while B requires 12 units.

Both of these products require a production time of 4 minutes and the total available working hours are 8 in a day.

What should be the production quantity for each of the products to maximize profits?

In this case, the objective function in the problem will be

Rank order analysis in R


X1 is the units of product A produced

X2 is the units of product B produced

X1 and x2 are also called decision variables.

The constraints are resources and time in this case.

Resource Constraint


Time Constraint


Let’s see how to resolve this problem in R

One sample analysis in R

Linear optimization using R

Load Packages


Decision Variables

Set the coefficients of the decision variables<-c(25,20)

Constraint Matrix

Create constraint matrix

Differences between Association and Correlation



Define the constraints


RHS for the constraints

Const.rhs<-c(Resouce_constraint, Time_constraint)


Constraints direction

Paired t test tabled value Vs p value


Optimal Solution


Optimal values for x1 and x2 are

45, 75

The value of the objective function at an optimal point is




From the above output, we can see that the company should produce 45 units of product A and 75 units of product B to get sales of $2625, which is the maximum sales that the company can get given the constraints.

LSTM Networks in R

About the author

Data Specialist

Leave a Reply

Your email address will not be published.

2 × one =