Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
cprasad111
Contributor II
Contributor II

Qlik R Integration - Ordering of data from Qlik to R is inconsistent

I'm trying to get statistical calculations done in R, but when Qlik sends data to R, it's not ordered correctly and hence the result which R returns is also sorted wrongly. Sometime the ordering is correct and sometimes it's wrong

Tried multiple ways

1. Only sending the data (AgeOfDeath)

R.ScriptEval('library("TTR");a<-RSI(ts(q$AgeOfDeath))', (Sum({<[Product_Category] = {'$(=GetFieldSelections ( Product_Category))'}>}sum_Notional_USD)/1000000000) as AgeOfDeath)

 

2. Sending the data and Report_Date (perhaps it'll make it order correctly)

R.ScriptEval('library("TTR");a<-RSI(ts(q$AgeOfDeath))',Report_Date as RDate, (Sum({<[Product_Category] = {'$(=GetFieldSelections ( Product_Category))'}>}sum_Notional_USD)/1000000000) as AgeOfDeath)

 

3. Creating a matrix using Report_Date and AgeOfDeath, Ordering by Report_Date column and then calling R function

R.ScriptEval('library("TTR");a<-c(q$rdate);b<-c(q$AgeOfDeath); m<-cbind(a, b); om<-m[order(a),]; ans<-RSI(ts(om[,"b"]));ans ', Report_Date as rdate, (Sum({<[Product_Category] = {'$(=GetFieldSelections ( Product_Category))'}>}sum_Notional_USD)/1000000000 ) as AgeOfDeath)

 

From the log what we observed is described below

Let's assume we have following data set

Report_Date |  AgeOfDeath

1 Jan |  11

2 Jan |  2

3 Jan | 33

.........

20 Jan | 2020

 

When Qlik passes to R, the first data point is randomly chosen and the ordering is from that randomly chose starting point. We want the starting point to be always 1 Jan | 11 in this case

9 Jan | 99

10 Jan | 1010

11 Jan | 1111

.....

20 Jan | 2020

1 Jan | 11

.....

8 Jan | 88

 

The blue line is the the one plotted by Qlik. The Red line is corresponding line plotted from returned result from R

Expected

expected.PNG

 

Actual

actual.PNG

Labels (4)
0 Replies