By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
SmartData Collective
  • Analytics
    AnalyticsShow More
    predictive analytics in dropshipping
    Predictive Analytics Helps New Dropshipping Businesses Thrive
    12 Min Read
    data-driven approach in healthcare
    The Importance of Data-Driven Approaches to Improving Healthcare in Rural Areas
    6 Min Read
    analytics for tax compliance
    Analytics Changes the Calculus of Business Tax Compliance
    8 Min Read
    big data analytics in gaming
    The Role of Big Data Analytics in Gaming
    10 Min Read
    analyst,women,looking,at,kpi,data,on,computer,screen
    Promising Benefits of Predictive Analytics in Asset Management
    11 Min Read
  • Big Data
  • BI
  • Exclusive
  • IT
  • Marketing
  • Software
Search
© 2008-23 SmartData Collective. All Rights Reserved.
Reading: Simple Inter-row Computation: esProc Keeps It Simple!
Share
Notification Show More
Latest News
ai software development
Key Strategies to Develop AI Software Cost-Effectively
Artificial Intelligence
ai in omnichannel marketing
AI is Driving Huge Changes in Omnichannel Marketing
Artificial Intelligence
ai for small business tax planning
Maximize Tax Deductions as a Business Owner with AI
Artificial Intelligence
ai in marketing with 3D rendering
Marketers Use AI to Take Advantage of 3D Rendering
Artificial Intelligence
How Big Data Is Transforming the Maritime Industry
How Big Data Is Transforming the Maritime Industry
Big Data
Aa
SmartData Collective
Aa
Search
  • About
  • Help
  • Privacy
Follow US
© 2008-23 SmartData Collective. All Rights Reserved.
SmartData Collective > R Programming Language > Simple Inter-row Computation: esProc Keeps It Simple!
R Programming Language

Simple Inter-row Computation: esProc Keeps It Simple!

raqsoft
Last updated: 2012/11/27 at 5:34 PM
raqsoft
7 Min Read
SHARE

The interrow computation is quite common, such as the aggregate, comparison with same period of any previous year, and link relative ratio in business statistics and analytics. Both R language and esProc provide a pretty good interrow computation ability with slight difference to each other. In the case below, the utilization of some basic inter-row computations is demonstrated to expound the differences between the two methods:

The interrow computation is quite common, such as the aggregate, comparison with same period of any previous year, and link relative ratio in business statistics and analytics. Both R language and esProc provide a pretty good interrow computation ability with slight difference to each other. In the case below, the utilization of some basic inter-row computations is demonstrated to expound the differences between the two methods:

Since Chrismas is coming, and the sales department of a company wants to make statistics on the outstanding sales persons after the chrismas big promotion, for example, the salesman who achieves half of the total sales amount of the company. The data are mainly from the order of table database: salesOrder. The main fields include the ID of order: ordered, Name of sales person: name, Sales amount: sales, and date of order: salesDate.

The straightforward solution is shown as below:

More Read

esProc Improves Text Processing: Fetching Data from a Batch of Files

Using esProc to Compute the Online Time of Users [PART 2]
Vector Computing, Who Is More Powerful, R Language or esProc?

1. Group by sales person to calculate the sales amount of each sales person.
2. Sort by sales amount in reverse order on the basis of the data from the previous step.
3. According to the previous step, calculate the aggregate value of each record, and calculate the standard of comparison: the half of total sales of this company.
4. Of the aggregate values calculated in the previous step, select out the list of sales persons whose sales achievement meeting the below conditions: lower or equal to the standard of comparison; or although higher than the standard of comparison, the sales achievement of previous sales person is lower than the standard of comparison.

The detailed solution of R is shown as below:

01 library(RODBC)
02 odbcDataSources()
03 conn<-odbcConnect(“sqlsvr”)
04 originalData<-sqlQuery(conn,’select * from salesOrder’)
05 odbcClose(conn)
06 nameSum<-gNameMonth<-aggregate(originalData$sales,list(originalData$name),sum)
07 names(nameSum)<-c(‘name’,’salesSum’)
08 orderData<-nameSum[rev(order(nameSum$salesSum)),]
09 halfSum<-sum(orderData$salesSum)/2
10 orderData$addup<-cumsum(orderData$salesSum)
11 subset(orderData,addup<=halfSum | (addup>halfSum & c( 0, addup[- length (addup)]) <halfSum))

 

Please find the detailed solution of esProc (download) below:

Then, let us study on the differences between aggregate values:

The R uses cumsum to calculate the aggregate value in the line 10.
esProc uses cumulate in A4 to calculate the aggregate value.

Both writing styles are very convenient for users. However, the operation principle of esProc is aimed to each record: firstly, calculate the cumulate, then, get the aggregate value corresponding to this record according to the # row number. By comparison, R enjoys a higher efficiency than esProc on this respect since the calculation will be executed only once.

Dividing one statement of esProc into two statements can solve the efficiency issue, that is, firstly, calculate the list of aggregate value separately, and then insert it to the original dataset. However, such writing style is not as concise as the R that only requires one line of code.

Then, let us check the qualified sales person and the differences:
R completes the computation at the Line 11, mainly by moving the line, and using c( 0, addup[- length (addup)]) to construct a column for the new data. Compared with the column addup, the new column just moves down one column, and the last entry of data is removed and filled with 0 of the first entry. Then, you can compare whether the aggregate value is lower than the standard of comparison, or although it is higher than the standard of comparison, its previous record is lower than the standard.

R does not provide the ability to access the data at the relative position. Therefore, the method of “move the data in the relative position to the current position” is adopted. Though the result is still the same, the style of writing is not intuitive enough, and it requires the analyst a relatively higher ability in logic thinking.

The writing style of esProc is select(addup<=B3 || (addup>B3 && addup[-1]. Excellent indeed! This is the expression of relative position featured by esProc. Users can use the method of [-1] to represent the record in a position one record before or several records after the current record. For example, the aggregation value calculation in A4 can also be rewritten to A3.derive(addup[-1]+salesSum:addup).

Unlike the fixed algorithm of aggregate value, the algorithm of this step is relatively much freer. You may find that the style of expression regarding the relative position of esProc is very agile with great advantages.

Compared with the fixed algorithms, this step of algorithm is much freer.

As we can see from the above case, the computations of relative position and interrow computations can solve many problems which are apparently complex. esProc is more flexible in expressing the relative positions. Therefore, esProc users can feel more relax when calculating the complex problems.

Regarding the R language, appending to the whole column/row and the fixed algorithm are relative more concise and very impressive.

For industries like marketing and sales, healthcare and pharmaceutical, educational, financial and telecommunication, statisticsl computing tools like R or esProc are usually helpful to ease working strength and improve efficiency.

Author: Jim King
BI technology consultant for Raqsoft
10 + years of experience on BI/OLAP application, statistical computing and analytics
Email: Contact@raqsoft.com
Website: www.raqsoft.com

TAGGED: esProc
raqsoft November 27, 2012
Share this Article
Facebook Twitter Pinterest LinkedIn
Share

Follow us on Facebook

Latest News

ai software development
Key Strategies to Develop AI Software Cost-Effectively
Artificial Intelligence
ai in omnichannel marketing
AI is Driving Huge Changes in Omnichannel Marketing
Artificial Intelligence
ai for small business tax planning
Maximize Tax Deductions as a Business Owner with AI
Artificial Intelligence
ai in marketing with 3D rendering
Marketers Use AI to Take Advantage of 3D Rendering
Artificial Intelligence

Stay Connected

1.2k Followers Like
33.7k Followers Follow
222 Followers Pin

You Might also Like

esProc Improves Text Processing: Fetching Data from a Batch of Files

6 Min Read

Using esProc to Compute the Online Time of Users [PART 2]

5 Min Read

Vector Computing, Who Is More Powerful, R Language or esProc?

6 Min Read

SmartData Collective is one of the largest & trusted community covering technical content about Big Data, BI, Cloud, Analytics, Artificial Intelligence, IoT & more.

AI chatbots
AI Chatbots Can Help Retailers Convert Live Broadcast Viewers into Sales!
Chatbots
AI and chatbots
Chatbots and SEO: How Can Chatbots Improve Your SEO Ranking?
Artificial Intelligence Chatbots Exclusive

Quick Link

  • About
  • Contact
  • Privacy
Follow US

© 2008-23 SmartData Collective. All Rights Reserved.

Removed from reading list

Undo
Go to mobile version
Welcome Back!

Sign in to your account

Lost your password?