I have been looking a bit into R lately. I have written here before about being able to transform R into something that can take real-time streams of data, or integrating R (or SPlus) into a CEP system. Here is a small example. Let's say that you want to take a sample of a "window" of streaming data every few seconds and compute some function on that sample.
Let's see how we can do this in R using static data.
In R, we can define a range of stock prices that range from $10.00 to $100.00, in increments of 25 cents.
> StockPrices<-seq(10.0, 100.0, 0.25)
 10.00 10.25 10.50 10.75 11.00 11.25 11.50 11.75 12.00 12.25 12.50 12.75 13.00 13.25 13.50 13.75 14.00
 99.25 99.50 99.75 100.00
We can take a sample of 10 random stock prices like this:
> sample(StockPrices, 10, rep=F)
 20.50 19.00 78.75 44.75 62.75 45.25 66.25 70.00 71.00 91.00
We can compute the average price of a sample of 10 random prices like this:
> mean(sample(StockPrices, 10, rep=F))
Using the Coral8 term of "window", let's say that we have a window called StockPrices that contains one minute's worth of prices. Every 5 seconds, we want to take a random sampling of 10 prices in that window and compute the average price of that random sample.
How can we do it in your CEP system? I would welcome examples in Coral8, Apama, Streambase, Aleri, Esper, StreamSQL, and any other CEP system.
©2009 Marc Adler - All Rights Reserved.
All opinions here are personal, and have no relation to my employer.