Hi Cliff,
following what I do in such a case:


Assuming your table is called t:

t[t==0] = NA
t = xts(interpNA(t, method="before"), index(t))


Regards,
Ulrich




On Sun, Oct 16, 2011 at 2:31 PM, Cliff Clive <cliffclive@gmail.com> wrote:

> I'm sure I've done this before but for the life of me I can't remember how.
>
> I'm working with a tick data series in the following format:
>
> /        Date    Time     Type  Price Quantity
> 2010-02-22 9:00:00 BEST_ASK 64.246        1
> 2010-02-22 9:00:10    TRADE 64.246      100
> 2010-02-22 9:00:10 BEST_ASK 64.260        1
> 2010-02-22 9:00:10 BEST_BID 64.232        1
> 2010-02-22 9:00:10 BEST_ASK 64.260        1
> 2010-02-22 9:00:10 BEST_BID 64.232        2/
>
> and I'm trying to add columns that give the most recent Bid, Ask, and Trade
> prices.
> So far I've done it using a for loop, but that's obviously way too slow.
>
> So I ran the following code:
> /StockA$LastBid = ifelse(StockA$Type=="BEST_BID",StockA$Price, 0)
> StockA$LastAsk = ifelse(StockA$Type=="BEST_ASK",StockA$Price, 0)
> StockA$LastTrade = ifelse(StockA$Type=="TRADE",StockA$Price, 0)/
>
> and turned the table into this:
> /        Date    Time     Type  Price Quantity LastBid LastAsk LastTrade
> 2010-02-22 9:00:00 BEST_ASK 64.246        1   0.000  64.246     0.000
> 2010-02-22 9:00:10    TRADE 64.246      100   0.000   0.000    64.246
> 2010-02-22 9:00:10 BEST_ASK 64.260        1   0.000  64.260     0.000
> 2010-02-22 9:00:10 BEST_BID 64.232        1  64.232   0.000     0.000
> 2010-02-22 9:00:10 BEST_ASK 64.260        1   0.000  64.260     0.000
> 2010-02-22 9:00:10 BEST_BID 64.232        2  64.232   0.000     0.000/
>
> Now is there a fast way to fill in the zeros between the observed prices?
> This is the part that kills me, since I'm pretty sure I've done something
> similar before, but I just can't remember what I did.
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Filling-a-time-series-with-Last-Ask-Last-Bid-etc-tp3909390p3909390.html
> Sent from the Rmetrics mailing list archive at Nabble.com.
>
> _______________________________________________
> R-SIG-Finance@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>

	[[alternative HTML version deleted]]

