<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Qlik R Integration - Ordering of data from Qlik to R is inconsistent in Integration, Extension &amp; APIs</title>
    <link>https://community.qlik.com/t5/Integration-Extension-APIs/Qlik-R-Integration-Ordering-of-data-from-Qlik-to-R-is/m-p/1547361#M10048</link>
    <description>&lt;P&gt;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&lt;/P&gt;&lt;P&gt;Tried multiple ways&lt;/P&gt;&lt;P&gt;1. Only sending the data (AgeOfDeath)&lt;/P&gt;&lt;P&gt;R.ScriptEval('library("TTR");a&amp;lt;-RSI(ts(q$AgeOfDeath))', (Sum({&amp;lt;[Product_Category] = {'$(=GetFieldSelections ( Product_Category))'}&amp;gt;}sum_Notional_USD)/1000000000) as AgeOfDeath)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Sending the data and Report_Date (perhaps it'll make it order correctly)&lt;/P&gt;&lt;P&gt;R.ScriptEval('library("TTR");a&amp;lt;-RSI(ts(q$AgeOfDeath))',Report_Date as RDate, (Sum({&amp;lt;[Product_Category] = {'$(=GetFieldSelections ( Product_Category))'}&amp;gt;}sum_Notional_USD)/1000000000) as AgeOfDeath)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. Creating a matrix using Report_Date and AgeOfDeath, Ordering by Report_Date column and then calling R function&lt;/P&gt;&lt;P&gt;R.ScriptEval('library("TTR");a&amp;lt;-c(q$rdate);b&amp;lt;-c(q$AgeOfDeath); m&amp;lt;-cbind(a, b); om&amp;lt;-m[order(a),]; ans&amp;lt;-RSI(ts(om[,"b"]));ans ', Report_Date as rdate, (Sum({&amp;lt;[Product_Category] = {'$(=GetFieldSelections ( Product_Category))'}&amp;gt;}sum_Notional_USD)/1000000000 ) as AgeOfDeath)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From the log what we observed is described below&lt;/P&gt;&lt;P&gt;Let's assume we have following data set&lt;/P&gt;&lt;P&gt;Report_Date |&amp;nbsp; AgeOfDeath&lt;/P&gt;&lt;P&gt;1 Jan |&amp;nbsp; 11&lt;/P&gt;&lt;P&gt;2 Jan |&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;3 Jan | 33&lt;/P&gt;&lt;P&gt;.........&lt;/P&gt;&lt;P&gt;20 Jan | 2020&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When Qlik passes to R, the first data point is randomly chosen and the ordering is from that randomly chose starting point. &lt;STRONG&gt;We want the starting point to be always 1 Jan | 11 in this case&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;9 Jan | 99&lt;/P&gt;&lt;P&gt;10 Jan | 1010&lt;/P&gt;&lt;P&gt;11 Jan | 1111&lt;/P&gt;&lt;P&gt;.....&lt;/P&gt;&lt;P&gt;20 Jan | 2020&lt;/P&gt;&lt;P&gt;1 Jan | 11&lt;/P&gt;&lt;P&gt;.....&lt;/P&gt;&lt;P&gt;8 Jan | 88&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The blue line is the the one plotted by Qlik. The Red line is corresponding line plotted from returned result from R&lt;/P&gt;&lt;P&gt;Expected&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="expected.PNG" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/6483i94DAD68C04BB239C/image-size/large?v=v2&amp;amp;px=999" role="button" title="expected.PNG" alt="expected.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actual&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="actual.PNG" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/6484i26509F998B9FD552/image-size/large?v=v2&amp;amp;px=999" role="button" title="actual.PNG" alt="actual.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 16 Nov 2024 21:22:19 GMT</pubDate>
    <dc:creator>cprasad111</dc:creator>
    <dc:date>2024-11-16T21:22:19Z</dc:date>
    <item>
      <title>Qlik R Integration - Ordering of data from Qlik to R is inconsistent</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Qlik-R-Integration-Ordering-of-data-from-Qlik-to-R-is/m-p/1547361#M10048</link>
      <description>&lt;P&gt;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&lt;/P&gt;&lt;P&gt;Tried multiple ways&lt;/P&gt;&lt;P&gt;1. Only sending the data (AgeOfDeath)&lt;/P&gt;&lt;P&gt;R.ScriptEval('library("TTR");a&amp;lt;-RSI(ts(q$AgeOfDeath))', (Sum({&amp;lt;[Product_Category] = {'$(=GetFieldSelections ( Product_Category))'}&amp;gt;}sum_Notional_USD)/1000000000) as AgeOfDeath)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Sending the data and Report_Date (perhaps it'll make it order correctly)&lt;/P&gt;&lt;P&gt;R.ScriptEval('library("TTR");a&amp;lt;-RSI(ts(q$AgeOfDeath))',Report_Date as RDate, (Sum({&amp;lt;[Product_Category] = {'$(=GetFieldSelections ( Product_Category))'}&amp;gt;}sum_Notional_USD)/1000000000) as AgeOfDeath)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. Creating a matrix using Report_Date and AgeOfDeath, Ordering by Report_Date column and then calling R function&lt;/P&gt;&lt;P&gt;R.ScriptEval('library("TTR");a&amp;lt;-c(q$rdate);b&amp;lt;-c(q$AgeOfDeath); m&amp;lt;-cbind(a, b); om&amp;lt;-m[order(a),]; ans&amp;lt;-RSI(ts(om[,"b"]));ans ', Report_Date as rdate, (Sum({&amp;lt;[Product_Category] = {'$(=GetFieldSelections ( Product_Category))'}&amp;gt;}sum_Notional_USD)/1000000000 ) as AgeOfDeath)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From the log what we observed is described below&lt;/P&gt;&lt;P&gt;Let's assume we have following data set&lt;/P&gt;&lt;P&gt;Report_Date |&amp;nbsp; AgeOfDeath&lt;/P&gt;&lt;P&gt;1 Jan |&amp;nbsp; 11&lt;/P&gt;&lt;P&gt;2 Jan |&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;3 Jan | 33&lt;/P&gt;&lt;P&gt;.........&lt;/P&gt;&lt;P&gt;20 Jan | 2020&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When Qlik passes to R, the first data point is randomly chosen and the ordering is from that randomly chose starting point. &lt;STRONG&gt;We want the starting point to be always 1 Jan | 11 in this case&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;9 Jan | 99&lt;/P&gt;&lt;P&gt;10 Jan | 1010&lt;/P&gt;&lt;P&gt;11 Jan | 1111&lt;/P&gt;&lt;P&gt;.....&lt;/P&gt;&lt;P&gt;20 Jan | 2020&lt;/P&gt;&lt;P&gt;1 Jan | 11&lt;/P&gt;&lt;P&gt;.....&lt;/P&gt;&lt;P&gt;8 Jan | 88&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The blue line is the the one plotted by Qlik. The Red line is corresponding line plotted from returned result from R&lt;/P&gt;&lt;P&gt;Expected&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="expected.PNG" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/6483i94DAD68C04BB239C/image-size/large?v=v2&amp;amp;px=999" role="button" title="expected.PNG" alt="expected.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actual&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="actual.PNG" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/6484i26509F998B9FD552/image-size/large?v=v2&amp;amp;px=999" role="button" title="actual.PNG" alt="actual.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 21:22:19 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Qlik-R-Integration-Ordering-of-data-from-Qlik-to-R-is/m-p/1547361#M10048</guid>
      <dc:creator>cprasad111</dc:creator>
      <dc:date>2024-11-16T21:22:19Z</dc:date>
    </item>
  </channel>
</rss>

