using [ on xts object
Dear Mr. or Mrs. Engineer, On Fri, Dec 23, 2011 at 1:50 PM, financial engineer
<fin_engr at hotmail.com> wrote:
I have the following sample tick data set (Z11): 24990 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24991 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24992 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24993 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24994 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24995 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24996 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24997 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24998 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24999 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B where the second field is the date, third- time, fourth - price, and fifth - bid, ask, or trade I have converted the above into a xts object using the following command z<-xts(Z11[,-1],order.by=as.Date(Z11[,1])) which has resulted in data in the following form 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" I want to split my data based on the hour of the day, ?so I was trying to use the following z['2011-10-31 04/'] to get the data starting from the 04 hour through the end of the day, but it returns the following: z['2011-10-31 04/'] ? ? trade_time trade_price trade_type can anyone pls. suggest how I can split the data into hourly intervals from this xts object.....thanks!
You can't. You created an xts object with a Date class index. The Date class doesn't contain any information about time of day. Use a date/time class (read ?DateTimeClasses). Subsetting xts objects by time of day has been discussed several times on this list. Please search the list archives (e.g. via rseek.org). Regards, -- Joshua Ulrich | FOSS Trading: www.fosstrading.com