Hi my xts structure is :
head(sym)
BidSize Bid Ask AskSize Quantity Mid
2006-01-04 09:01:00 3771 181000 182000 5783 15625 181500
2006-01-04 09:02:00 3952 181000 182000 5659 180 181500
2006-01-04 09:03:00 3556 181000 182000 5943 1059 181500
2006-01-04 09:04:00 3747 181000 182000 6133 261 181500
2006-01-04 09:05:00 3957 181000 182000 6077 101 181500
2006-01-04 09:06:00 3898 181000 182000 6511 311 181500
I have a function getTickSize(x,date) which is designed for x as a single numeric (not an array).
I would like if possible to replace the following for loop by a “smart” call to the apply family of functions
for (i in 1:nrow(sym[1:10])){
sym$TS[i] <- getTickSize(sym$Mid[i],index(sym)[i])
}
Any pointer ? all my attempts were met with the following warnings:
the condition has length > 1 and only the first element will be used
I believe in this case,
mapplyis the easiest solution:Note: the
*applyfamily of functions is not always better than a simple loop (most of the myth around that dates way back to early version of S).But I admit it looks a lot sexier.