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

pierre8r-list at yahoo.fr pierre8r-list at yahoo.fr
Thu Jul 17 12:24:13 CEST 2008


Jeff Ryan <jeff.a.ryan <at> gmail.com> writes:

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


Hi jeff,

Thanks for the answer.

Because I need to compare two files, I have to format the csv file.
To compare the two files I use WinMerge :
http://winmerge.org/

I have slightly changed your code to :

x <- matrix(c(strftime(as.POSIXlt(index(x)),'%m/%d/%Y,%H:%M'),
 format(x, nsmall = 5)), ncol=2)

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

But I need a space between the comma and the double, like that :
The current output :
01/08/2007,00:59,1.93025
01/08/2007,01:59,1.92955
01/08/2007,02:59,1.92885

My target :
01/08/2007,00:59, 1.93025
01/08/2007,01:59, 1.92955
01/08/2007,02:59, 1.92885

Also is it possible to remove the first line ( the V1,V2 stuff ) ?

V1,V2
07/17/2008,12:18,1.960615
07/17/2008,12:18,1.940416
07/17/2008,12:18,1.931146


Thanks,

Pierre8r


      ____________________________________________________
intelligente http://mail.yahoo.fr



More information about the R-SIG-Finance mailing list