Don't success to create xts from lines in code
I would read it as a data.frame, since the index has a comma, then
convert to xts.
quotes <- read.csv(textConnection(lines), header=FALSE)
x <- as.xts(quotes[,-(1:2)],
as.POSIXct(paste(quotes[,1],quotes[,2]),format='%Y.%m.%d %H:%M'))
colnames(x) <- c('Open','High','Low','Close','Volume')
--
http://quantemplation.blogspot.com
On Thu, Jul 24, 2008 at 1:59 PM, <pierre8r-list at yahoo.fr> wrote:
Hi Josh, Thanks, it works. If it don't boring you, I want to read a other data format. There is a comma between Date and Time. 2008.07.14,04:00,1.5894,1.5916,1.5893,1.5914,276 2008.07.14,05:00,1.5912,1.5912,1.5902,1.5904,205 2008.07.14,06:00,1.5903,1.5911,1.5898,1.5899,239 2008.07.14,07:00,1.5898,1.5902,1.5865,1.5882,541 2008.07.14,08:00,1.5883,1.5910,1.5868,1.5870,689 2008.07.14,09:00,1.5869,1.5890,1.5860,1.5877,763 2008.07.14,10:00,1.5878,1.5881,1.5841,1.5871,835 2008.07.14,11:00,1.5870,1.5876,1.5854,1.5859,533 Thanks, Pierre8r
See ?read.zoo
1) You need to specify the correct delimiter for your file.
2) read.zoo is converting your index to Date (the default),
use
POSIXct instead and be sure to specify the correct format
of the index
in your file.
quotes <- read.zoo(textConnection(Lines),
sep=',',
FUN=as.POSIXct, format='%m/%d/%Y %H:%M:%S')
x <- as.xts(quotes)
colnames(x) <-
c('Open','High','Low','Close','Volume')
--
http://quantemplation.blogspot.com
____________________________________________________________ ente http://mail.yahoo.fr _______________________________________________ R-SIG-Finance at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. -- If you want to post, subscribe first.