I have studied Brian Bauer's post and have successfully run the Comorbidity app (very helpful). I tried to mimic the script logic using the following script below but encounter an argument error:
SET QvWorkPath='C:\QlikWarehouse\POC Development\Comorbidity\Qlik AAI Load Script Example - R';
R.ScriptEval('starttime <- proc.time(); source(q$RSource); elapsed <- proc.time()-starttime; toString(unname(elapsed["elapsed"]));', RSource) as [Elapsed Time];
'$(RSource)' as RSource
if you want to do this is real time as a chart expression (with changes based upon selection), then to get a different granularity of input data to output data then the best way is to use an AGGR function.
But as per the previous answer, if you just need it as a one time thing against the whole data set, then running in the script is a better option.