[R-SIG-Finance] How to format a CSV file output ?

Jeff Ryan jeff.a.ryan at gmail.com
Wed Jul 16 17:05:29 CEST 2008


Hi Pierre,

try:

x <- xts(matrix(runif(10,1.9,2)), Sys.time()+1:10)

x <- matrix(c(strftime(as.POSIXlt(index(x)),'%m/%d/%Y,%H:%M'),x),dimnames=list(NULL,c('','Indec')),nc=2)

write.csv(x, row.names=FALSE, quote=FALSE)

,Indec
07/16/2008,14:59,1.92998949340545
07/16/2008,14:59,1.92604529005475
07/16/2008,14:59,1.90992500772700
07/16/2008,14:59,1.90918286179658
07/16/2008,14:59,1.98319136707578
07/16/2008,14:59,1.95377100475598
07/16/2008,14:59,1.90766719337553
07/16/2008,14:59,1.9713675866602
07/16/2008,14:59,1.94339190139435
07/16/2008,14:59,1.95427884196397

HTH
Jeff

On Wed, Jul 16, 2008 at 9:32 AM,  <pierre8r-list at yahoo.fr> wrote:
> Hello,
>
> Here my R code :
>
> library(xts)
> library(quantmod)
>
> quotes <- read.csv2("E:\\00001-Compare\\Output\\OutputJBacktesting\\InputIndic.txt",
> header = FALSE, sep = ",", dec=".")
>
> x <- xts(as.matrix(quotes[,-1]),as.POSIXct(paste(quotes[,1]),format='%m/%d/%Y
> %H:%M'))
> colnames(x) <- c('Indic')
> x
>
> write.csv(x, file = "OutputIndic.csv", quote = FALSE, row.names = FALSE)
>
> The x give this output to the R Console :
>
>> colnames(x) <- c('Indic')
>> x
>                      Indic
> 2007-01-08 00:59:00 1.93025
> 2007-01-08 01:59:00 1.92960
> 2007-01-08 02:59:00 1.92805
>
>
> My goal is to generate this kind of CSV output :
>
> 01/08/2007,00:59, 1.93025
> 01/08/2007,01:59, 1.92955
> 01/08/2007,02:59, 1.92885
>
> My write.csv generate this CSV output :
>
> Indic
> 1.93025
> 1.9296
> 1.92805
>
> How to generate this kind of output ?
>
> 01/08/2007,00:59, 1.93025
> 01/08/2007,01:59, 1.92955
>
> Thanks,
>
> Pierre8r
>
>
>
>      ____________________________________________________________
> 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.
>



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list