Re: [R] How to change the default Date format for write.csv function?

2009-12-28 Thread Henrique Dallazuanna
Try this:

cat('"', paste(names(newD), collapse = '","'), '"\n', sep = '', file =
'temp.txt', append = TRUE)
cat(paste(apply(newD, 1,
function(l)paste('"', l[1], '",', l[2], ',', l[3], sep = "")),
  collapse = "\n"), file = 'temp.txt', append = TRUE)


Using newD object from my previous email

On Mon, Dec 28, 2009 at 3:52 PM,  wrote:

>
> Nice try, but that will turn off quote for all fields.  I want quotes for
> text fields, and no quotes for date and numeric fields.   Please see the
> desired CSV output in my previous email.
>
> George
>
>
>  From: Henrique Dallazuanna  To:
> george@bnymellon.com Cc:
> r-help@r-project.org
> Date: 12/28/2009 12:44 PM Subject: Re: [R] How to change the default Date
> format for write.csvfunction?
>  Sent by: r-help-boun...@r-project.org
> --
>
>
>
> Use the quote argument:
>
> write.csv(d, file="C:/temp/test.csv", row.names=FALSE, quote = FALSE)
>
> On Mon, Dec 28, 2009 at 2:17 PM,   wrote:
> > Hi,
> >
> > This problem might be a little harder than it appears.
> >
> > I receive a few emails all suggesting that convert the Date field to
> > character by calling format(date, "%m/%d/%Y") in one way or another.
> Well,
> > this is not the solution I'm looking for and it doesn't work for me.
> All
> > the date fields are generated with quotes around them, which will be
> > treated by other software as string instead of date.   Please note, the
> > write.csv() function doesn't put quotes around date.   All I need is to
> > change the format behavior of Date without adding any quotes.  So the
> > output of CSV I'm looking for should be:
> >
> > "ticker","date","price"
> > "IBM",12/03/2009,120
> > "IBM",12/04/2009,123
> >
> > Not this:
> >
> > "ticker","date","price"
> > "IBM","12/03/2009",120
> > "IBM","12/04/2009",123
> >
> > Thanks for trying though.
> >
> > George
> >
> >
> >
> > From:
> > george@bnymellon.com
> > To:
> > r-help@r-project.org
> > Date:
> > 12/28/2009 10:20 AM
> > Subject:
> > [R] How to change the default Date format for write.csv function?
> > Sent by:
> > r-help-boun...@r-project.org
> >
> >
> >
> > Hi,
> >
> > I have a data.frame containing a Date column.  When using write.csv()
> > function to generate a CSV file, I always get the Date column formatted
> as
> >
> > "-MM-DD".   I would like to have it formatted as "MM/DD/", but
> > could not find an  easy way to do it.Here is the test code:
> >
> > d <- data.frame(ticker=c("IBM", "IBM"), date = as.Date(c("2009-12-03",
> > "2009-12-04")), price=c(120.00, 123.00))
> > write.csv(d, file="C:/temp/test.csv", row.names=FALSE)
> >
> > The test.csv generated looks like this:
> >
> > "ticker","date","price"
> > "IBM",2009-12-03,120
> > "IBM",2009-12-04,123
> >
> > I would like to have the date fields in the CSV formatted as
> "MM/DD/".
> >
> >  Is there any easy way to do this?
> >
> > Thanks in advance.
> >
> > George Zou
> >
> > The information contained in this e-mail, and any attachment, is
> > confidential and is intended solely for the use of the intended
> recipient.
> > Access, copying or re-use of the e-mail or any attachment, or any
> > information contained therein, by any other person is not authorized. If
> > you are not the intended recipient please return the e-mail to the sender
> > and delete it from your computer. Although we attempt to sweep e-mail and
> > attachments for viruses, we do not guarantee that either are virus-free
> > and accept no liability for any damage sustained as a result of viruses.
> >
> > Please refer to http://disclaimer.bnymellon.com/eu.htm for certain
> > disclosures relating to European legal entities.
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html

Re: [R] How to change the default Date format for write.csv function?

2009-12-28 Thread George . Zou
Nice try, but that will turn off quote for all fields.  I want quotes for 
text fields, and no quotes for date and numeric fields.   Please see the 
desired CSV output in my previous email. 

George



From:
Henrique Dallazuanna 
To:
george@bnymellon.com
Cc:
r-help@r-project.org
Date:
12/28/2009 12:44 PM
Subject:
Re: [R] How to change the default Date format for write.csv function?
Sent by:
r-help-boun...@r-project.org



Use the quote argument:

write.csv(d, file="C:/temp/test.csv", row.names=FALSE, quote = FALSE)

On Mon, Dec 28, 2009 at 2:17 PM,   wrote:
> Hi,
>
> This problem might be a little harder than it appears.
>
> I receive a few emails all suggesting that convert the Date field to
> character by calling format(date, "%m/%d/%Y") in one way or another. 
Well,
> this is not the solution I'm looking for and it doesn't work for me.   
All
> the date fields are generated with quotes around them, which will be
> treated by other software as string instead of date.   Please note, the
> write.csv() function doesn't put quotes around date.   All I need is to
> change the format behavior of Date without adding any quotes.  So the
> output of CSV I'm looking for should be:
>
> "ticker","date","price"
> "IBM",12/03/2009,120
> "IBM",12/04/2009,123
>
> Not this:
>
> "ticker","date","price"
> "IBM","12/03/2009",120
> "IBM","12/04/2009",123
>
> Thanks for trying though.
>
> George
>
>
>
> From:
> george@bnymellon.com
> To:
> r-help@r-project.org
> Date:
> 12/28/2009 10:20 AM
> Subject:
> [R] How to change the default Date format for write.csv function?
> Sent by:
> r-help-boun...@r-project.org
>
>
>
> Hi,
>
> I have a data.frame containing a Date column.  When using write.csv()
> function to generate a CSV file, I always get the Date column formatted 
as
>
> "-MM-DD".   I would like to have it formatted as "MM/DD/", but
> could not find an  easy way to do it.Here is the test code:
>
> d <- data.frame(ticker=c("IBM", "IBM"), date = as.Date(c("2009-12-03",
> "2009-12-04")), price=c(120.00, 123.00))
> write.csv(d, file="C:/temp/test.csv", row.names=FALSE)
>
> The test.csv generated looks like this:
>
> "ticker","date","price"
> "IBM",2009-12-03,120
> "IBM",2009-12-04,123
>
> I would like to have the date fields in the CSV formatted as 
"MM/DD/".
>
>  Is there any easy way to do this?
>
> Thanks in advance.
>
> George Zou
>
> The information contained in this e-mail, and any attachment, is
> confidential and is intended solely for the use of the intended 
recipient.
> Access, copying or re-use of the e-mail or any attachment, or any
> information contained therein, by any other person is not authorized. If
> you are not the intended recipient please return the e-mail to the 
sender
> and delete it from your computer. Although we attempt to sweep e-mail 
and
> attachments for viruses, we do not guarantee that either are virus-free
> and accept no liability for any damage sustained as a result of viruses.
>
> Please refer to http://disclaimer.bnymellon.com/eu.htm for certain
> disclosures relating to European legal entities.
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
> The information contained in this e-mail, and any attachment, is 
confidential and is intended solely for the use of the intended recipient. 
Access, copying or re-use of the e-mail or any attachment, or any 
information contained therein, by any other person is not authorized. If 
you are not the intended recipient please return the e-mail to the sender 
and delete it from your computer. Although we attempt to sweep e-mail and 
attachments for viruses, we do not guarantee that either are virus-free 
and accept no liability for any damage sustained as a result of viruses.
>
> Please refer to http://disclaimer.bnymellon.com/eu.htm for certain 
disclosures relating to European legal entities.
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.

Re: [R] How to change the default Date format for write.csv function?

2009-12-28 Thread Henrique Dallazuanna
Use the quote argument:

write.csv(d, file="C:/temp/test.csv", row.names=FALSE, quote = FALSE)

On Mon, Dec 28, 2009 at 2:17 PM,   wrote:
> Hi,
>
> This problem might be a little harder than it appears.
>
> I receive a few emails all suggesting that convert the Date field to
> character by calling format(date, "%m/%d/%Y") in one way or another. Well,
> this is not the solution I'm looking for and it doesn't work for me.   All
> the date fields are generated with quotes around them, which will be
> treated by other software as string instead of date.   Please note, the
> write.csv() function doesn't put quotes around date.   All I need is to
> change the format behavior of Date without adding any quotes.  So the
> output of CSV I'm looking for should be:
>
> "ticker","date","price"
> "IBM",12/03/2009,120
> "IBM",12/04/2009,123
>
> Not this:
>
> "ticker","date","price"
> "IBM","12/03/2009",120
> "IBM","12/04/2009",123
>
> Thanks for trying though.
>
> George
>
>
>
> From:
> george@bnymellon.com
> To:
> r-help@r-project.org
> Date:
> 12/28/2009 10:20 AM
> Subject:
> [R] How to change the default Date format for write.csv function?
> Sent by:
> r-help-boun...@r-project.org
>
>
>
> Hi,
>
> I have a data.frame containing a Date column.  When using write.csv()
> function to generate a CSV file, I always get the Date column formatted as
>
> "-MM-DD".   I would like to have it formatted as "MM/DD/", but
> could not find an  easy way to do it.    Here is the test code:
>
> d <- data.frame(ticker=c("IBM", "IBM"), date = as.Date(c("2009-12-03",
> "2009-12-04")), price=c(120.00, 123.00))
> write.csv(d, file="C:/temp/test.csv", row.names=FALSE)
>
> The test.csv generated looks like this:
>
> "ticker","date","price"
> "IBM",2009-12-03,120
> "IBM",2009-12-04,123
>
> I would like to have the date fields in the CSV formatted as "MM/DD/".
>
>  Is there any easy way to do this?
>
> Thanks in advance.
>
> George Zou
>
> The information contained in this e-mail, and any attachment, is
> confidential and is intended solely for the use of the intended recipient.
> Access, copying or re-use of the e-mail or any attachment, or any
> information contained therein, by any other person is not authorized. If
> you are not the intended recipient please return the e-mail to the sender
> and delete it from your computer. Although we attempt to sweep e-mail and
> attachments for viruses, we do not guarantee that either are virus-free
> and accept no liability for any damage sustained as a result of viruses.
>
> Please refer to http://disclaimer.bnymellon.com/eu.htm for certain
> disclosures relating to European legal entities.
>                 [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
> The information contained in this e-mail, and any attachment, is confidential 
> and is intended solely for the use of the intended recipient. Access, copying 
> or re-use of the e-mail or any attachment, or any information contained 
> therein, by any other person is not authorized. If you are not the intended 
> recipient please return the e-mail to the sender and delete it from your 
> computer. Although we attempt to sweep e-mail and attachments for viruses, we 
> do not guarantee that either are virus-free and accept no liability for any 
> damage sustained as a result of viruses.
>
> Please refer to http://disclaimer.bnymellon.com/eu.htm for certain 
> disclosures relating to European legal entities.
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to change the default Date format for write.csv function?

2009-12-28 Thread George . Zou
Hi,

This problem might be a little harder than it appears. 

I receive a few emails all suggesting that convert the Date field to 
character by calling format(date, "%m/%d/%Y") in one way or another. Well, 
this is not the solution I'm looking for and it doesn't work for me.   All 
the date fields are generated with quotes around them, which will be 
treated by other software as string instead of date.   Please note, the 
write.csv() function doesn't put quotes around date.   All I need is to 
change the format behavior of Date without adding any quotes.  So the 
output of CSV I'm looking for should be:

"ticker","date","price"
"IBM",12/03/2009,120
"IBM",12/04/2009,123

Not this:

"ticker","date","price"
"IBM","12/03/2009",120
"IBM","12/04/2009",123

Thanks for trying though.

George



From:
george@bnymellon.com
To:
r-help@r-project.org
Date:
12/28/2009 10:20 AM
Subject:
[R] How to change the default Date format for write.csv function?
Sent by:
r-help-boun...@r-project.org



Hi,

I have a data.frame containing a Date column.  When using write.csv() 
function to generate a CSV file, I always get the Date column formatted as 

"-MM-DD".   I would like to have it formatted as "MM/DD/", but 
could not find an  easy way to do it.Here is the test code:

d <- data.frame(ticker=c("IBM", "IBM"), date = as.Date(c("2009-12-03", 
"2009-12-04")), price=c(120.00, 123.00))
write.csv(d, file="C:/temp/test.csv", row.names=FALSE)

The test.csv generated looks like this:

"ticker","date","price"
"IBM",2009-12-03,120
"IBM",2009-12-04,123

I would like to have the date fields in the CSV formatted as "MM/DD/". 

 Is there any easy way to do this?

Thanks in advance.

George Zou

The information contained in this e-mail, and any attachment, is 
confidential and is intended solely for the use of the intended recipient. 
Access, copying or re-use of the e-mail or any attachment, or any 
information contained therein, by any other person is not authorized. If 
you are not the intended recipient please return the e-mail to the sender 
and delete it from your computer. Although we attempt to sweep e-mail and 
attachments for viruses, we do not guarantee that either are virus-free 
and accept no liability for any damage sustained as a result of viruses. 

Please refer to http://disclaimer.bnymellon.com/eu.htm for certain 
disclosures relating to European legal entities.
 [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




The information contained in this e-mail, and any attachment, is confidential 
and is intended solely for the use of the intended recipient. Access, copying 
or re-use of the e-mail or any attachment, or any information contained 
therein, by any other person is not authorized. If you are not the intended 
recipient please return the e-mail to the sender and delete it from your 
computer. Although we attempt to sweep e-mail and attachments for viruses, we 
do not guarantee that either are virus-free and accept no liability for any 
damage sustained as a result of viruses. 

Please refer to http://disclaimer.bnymellon.com/eu.htm for certain disclosures 
relating to European legal entities.
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to change the default Date format for write.csv function?

2009-12-28 Thread Gabor Grothendieck
Try this:

> write.csv(transform(d, date = format(date, "%m/%d/%Y")))
"","ticker","date","price"
"1","IBM","12/03/2009",120
"2","IBM","12/04/2009",123


On Mon, Dec 28, 2009 at 10:19 AM,   wrote:
> Hi,
>
> I have a data.frame containing a Date column.  When using write.csv()
> function to generate a CSV file, I always get the Date column formatted as
> "-MM-DD".   I would like to have it formatted as "MM/DD/", but
> could not find an  easy way to do it.    Here is the test code:
>
> d <- data.frame(ticker=c("IBM", "IBM"), date = as.Date(c("2009-12-03",
> "2009-12-04")), price=c(120.00, 123.00))
> write.csv(d, file="C:/temp/test.csv", row.names=FALSE)
>
> The test.csv generated looks like this:
>
> "ticker","date","price"
> "IBM",2009-12-03,120
> "IBM",2009-12-04,123
>
> I would like to have the date fields in the CSV formatted as "MM/DD/".
>  Is there any easy way to do this?
>
> Thanks in advance.
>
> George Zou
>
> The information contained in this e-mail, and any attachment, is confidential 
> and is intended solely for the use of the intended recipient. Access, copying 
> or re-use of the e-mail or any attachment, or any information contained 
> therein, by any other person is not authorized. If you are not the intended 
> recipient please return the e-mail to the sender and delete it from your 
> computer. Although we attempt to sweep e-mail and attachments for viruses, we 
> do not guarantee that either are virus-free and accept no liability for any 
> damage sustained as a result of viruses.
>
> Please refer to http://disclaimer.bnymellon.com/eu.htm for certain 
> disclosures relating to European legal entities.
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to change the default Date format for write.csv function?

2009-12-28 Thread Henrique Dallazuanna
Try this:

newD <- replace(d, sapply(d, function(x)inherits(x, "Date")),
format(d[sapply(d, function(x)inherits(x, "Date"))], "%m/%d/%Y"))
write.csv(newD, file="C:/temp/test.csv", row.names=FALSE)

On Mon, Dec 28, 2009 at 1:19 PM,   wrote:
> Hi,
>
> I have a data.frame containing a Date column.  When using write.csv()
> function to generate a CSV file, I always get the Date column formatted as
> "-MM-DD".   I would like to have it formatted as "MM/DD/", but
> could not find an  easy way to do it.    Here is the test code:
>
> d <- data.frame(ticker=c("IBM", "IBM"), date = as.Date(c("2009-12-03",
> "2009-12-04")), price=c(120.00, 123.00))
> write.csv(d, file="C:/temp/test.csv", row.names=FALSE)
>
> The test.csv generated looks like this:
>
> "ticker","date","price"
> "IBM",2009-12-03,120
> "IBM",2009-12-04,123
>
> I would like to have the date fields in the CSV formatted as "MM/DD/".
>  Is there any easy way to do this?
>
> Thanks in advance.
>
> George Zou
>
> The information contained in this e-mail, and any attachment, is confidential 
> and is intended solely for the use of the intended recipient. Access, copying 
> or re-use of the e-mail or any attachment, or any information contained 
> therein, by any other person is not authorized. If you are not the intended 
> recipient please return the e-mail to the sender and delete it from your 
> computer. Although we attempt to sweep e-mail and attachments for viruses, we 
> do not guarantee that either are virus-free and accept no liability for any 
> damage sustained as a result of viruses.
>
> Please refer to http://disclaimer.bnymellon.com/eu.htm for certain 
> disclosures relating to European legal entities.
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to change the default Date format for write.csv function?

2009-12-28 Thread jim holtman
try this:

d <- data.frame(ticker=c("IBM", "IBM"), date = as.Date(c("2009-12-03",
"2009-12-04")), price=c(120.00, 123.00))
# convert to your desired format
d$mydate <- format(d$date, "%m/%d/%Y")
write.csv(subset(d, select=-date), file="C:/temp/test.csv", row.names=FALSE)


On Mon, Dec 28, 2009 at 10:19 AM,  wrote:

> Hi,
>
> I have a data.frame containing a Date column.  When using write.csv()
> function to generate a CSV file, I always get the Date column formatted as
> "-MM-DD".   I would like to have it formatted as "MM/DD/", but
> could not find an  easy way to do it.Here is the test code:
>
> d <- data.frame(ticker=c("IBM", "IBM"), date = as.Date(c("2009-12-03",
> "2009-12-04")), price=c(120.00, 123.00))
> write.csv(d, file="C:/temp/test.csv", row.names=FALSE)
>
> The test.csv generated looks like this:
>
> "ticker","date","price"
> "IBM",2009-12-03,120
> "IBM",2009-12-04,123
>
> I would like to have the date fields in the CSV formatted as "MM/DD/".
>  Is there any easy way to do this?
>
> Thanks in advance.
>
> George Zou
>
> The information contained in this e-mail, and any attachment, is
> confidential and is intended solely for the use of the intended recipient.
> Access, copying or re-use of the e-mail or any attachment, or any
> information contained therein, by any other person is not authorized. If you
> are not the intended recipient please return the e-mail to the sender and
> delete it from your computer. Although we attempt to sweep e-mail and
> attachments for viruses, we do not guarantee that either are virus-free and
> accept no liability for any damage sustained as a result of viruses.
>
> Please refer to http://disclaimer.bnymellon.com/eu.htm for certain
> disclosures relating to European legal entities.
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How to change the default Date format for write.csv function?

2009-12-28 Thread George . Zou
Hi,

I have a data.frame containing a Date column.  When using write.csv() 
function to generate a CSV file, I always get the Date column formatted as 
"-MM-DD".   I would like to have it formatted as "MM/DD/", but 
could not find an  easy way to do it.Here is the test code:

d <- data.frame(ticker=c("IBM", "IBM"), date = as.Date(c("2009-12-03", 
"2009-12-04")), price=c(120.00, 123.00))
write.csv(d, file="C:/temp/test.csv", row.names=FALSE)

The test.csv generated looks like this:

"ticker","date","price"
"IBM",2009-12-03,120
"IBM",2009-12-04,123

I would like to have the date fields in the CSV formatted as "MM/DD/". 
 Is there any easy way to do this?

Thanks in advance.

George Zou

The information contained in this e-mail, and any attachment, is confidential 
and is intended solely for the use of the intended recipient. Access, copying 
or re-use of the e-mail or any attachment, or any information contained 
therein, by any other person is not authorized. If you are not the intended 
recipient please return the e-mail to the sender and delete it from your 
computer. Although we attempt to sweep e-mail and attachments for viruses, we 
do not guarantee that either are virus-free and accept no liability for any 
damage sustained as a result of viruses. 

Please refer to http://disclaimer.bnymellon.com/eu.htm for certain disclosures 
relating to European legal entities.
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.