Re: [R] Aggragating subsets of data in larger vector with sapply

2011-01-11 Thread Joshua Ulrich
Hi Chris, This seems to work on the sample data you provided. FUN <- function(x) { x <- xts(as.numeric(x),index(x)) period.apply(x, endpoints(x,"secs"), sum) } lapply(split.default(xSym$Size,xSym$Direction), FUN) Best, -- Joshua Ulrich  |  FOSS Trading: www.fosstrading.com On Sun, Jan 9,

Re: [R] Aggragating subsets of data in larger vector with sapply

2011-01-09 Thread Jim Holtman
split the data by truncating the time to a second, then process each group. this will save the subsetting you are doing. also merge the data with direction and size in the same frame. it looks like you can subset by "buy" to begin with. Sent from my iPad On Jan 9, 2011, at 19:10, rivercode w

[R] Aggragating subsets of data in larger vector with sapply

2011-01-09 Thread rivercode
Have 40,000 rows of buy/sell trade data and am trying to add up the buys for each second, the code works but it is very slow. Any suggestions how to improve the sapply function ? secEP = endpoints(xSym$Direction, "secs") # vector of last second on an XTS timeseries object with multiple entries