[R] How to format the output file just the way I want ?

pierre8r-nabble at yahoo.fr pierre8r-nabble at yahoo.fr
Sat Aug 2 18:52:36 CEST 2008


Hello,

How to format the output file just the way I want ?

Thanks,

Pierre8r


Output file format I am looking for :
------------------------------------
2008.07.01,02:00,1.5761,1.5766,1.5760,1.5763,65
2008.07.01,02:15,1.5762,1.5765,1.5757,1.5761,95
2008.07.01,02:30,1.5762,1.5765,1.5758,1.5759,58
2008.07.01,02:45,1.5758,1.5758,1.5745,1.5746,91


Output file format I get :
--------------------------
2008.07.01,02:00,  1.5761,  1.5766,  1.5760,  1.5763, 65.0000
2008.07.01,02:15,  1.5762,  1.5765,  1.5757,  1.5761, 95.0000
2008.07.01,02:30,  1.5762,  1.5765,  1.5758,  1.5759, 58.0000
2008.07.01,02:45,  1.5758,  1.5758,  1.5745,  1.5746, 91.0000


My R code :
-----------

library(quantmod)
library(xts)

Lines <-
"2008.07.01,02:00,1.5761,1.5766,1.5760,1.5763,65
2008.07.01,02:15,1.5762,1.5765,1.5757,1.5761,95
2008.07.01,02:30,1.5762,1.5765,1.5758,1.5759,58
2008.07.01,02:45,1.5758,1.5758,1.5745,1.5746,91
2008.07.01,03:00,1.5745,1.5751,1.5744,1.5744,117
2008.07.01,03:15,1.5742,1.5742,1.5727,1.5729,100
2008.07.01,03:30,1.5730,1.5736,1.5730,1.5736,61
2008.07.01,03:45,1.5735,1.5740,1.5735,1.5739,55"

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')

x

write.table(format(x,nsmall=4),
file = "K:\\OutputFile.csv", quote=FALSE,  col.names=FALSE,
row.names=format(index(x),"%Y.%m.%d,%H:%M"),  sep=",")






      ____________________________________________________________


More information about the R-help mailing list