[R] How to fix the format in write.csv
By dafault, write.csv will change the characters such as 5/38 as a date May-38. How can I not change the format? Thanks. ChangJiang [[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 fix the format in write.csv
Read your Excel documentation. AFAIK, R just writes text files -- you need to tell Excel how to read them in. Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Fri, May 2, 2014 at 11:34 AM, ChangJiang Xu changjiang.h...@gmail.com wrote: By dafault, write.csv will change the characters such as 5/38 as a date May-38. How can I not change the format? Thanks. ChangJiang [[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 fix the format in write.csv
ChangJiang: Open the .csv file with Notepad or other plain vanilla text processor, NOT EXCEL. You will find that the columns are text. Excel automatically converts them to dates. Read Excel's docs or get help from someone to learn how to convert the dates back to text. -- Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Fri, May 2, 2014 at 12:35 PM, ChangJiang Xu changjiang.h...@gmail.com wrote: Thanks. I still didn't get the solution. For example, I have a data frame, called temp temp Chr Ref Var AFFUNAFF AFF.test pvalue 1 10 A G 2/1/240/0/1905/49 2.429e-09 2 18 G A 1/9/17 0/23/167 11/43 2.484e-04 3 1 G A 2/2/220/8/176 6/46 4.293e-04 4 11 T G 1/1/250/2/188 3/51 1.193e-03 5 2 A T 1/10/16 38/90/60 12/42 2.220e-03 6 3 G A 1/16/10 8/49/13318/36 4.549e-03 Then I want to write a csv file using R function write.csv, as follows: write.csv(temp, file=temp.csv, row.names = FALSE) and the csv file, temp.csv, looks like the below, not same as original data ChrRefVarAFF UNAFFAFF.testpvalue 10AG02/01/20240/0/190May-492.43E-09 18GA01/09/20170/23/167 Nov-430.0002484 1 GA02/02/20220/8/176Jun-460.0004293 11 TG01/01/20250/2/188Mar-510.001193 2 AT01/10/201638/90/60 Dec-420.00222 3 GA1/16/108/49/133 18/36 0.004549 On Fri, May 2, 2014 at 3:06 PM, Bert Gunter gunter.ber...@gene.com wrote: Read your Excel documentation. AFAIK, R just writes text files -- you need to tell Excel how to read them in. Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Fri, May 2, 2014 at 11:34 AM, ChangJiang Xu changjiang.h...@gmail.com wrote: By dafault, write.csv will change the characters such as 5/38 as a date May-38. How can I not change the format? Thanks. ChangJiang [[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 fix the format in write.csv
Hi ChangJiang, Date conversion is one of the biggest headaches with Excel. Even if you import those data into Excel and then specify that the column should be text format, it won't convert the values back into what they originally were. Be aware that Excel may, when encountering dates from a different locale, _silently_ convert the ones that aren't valid in its current locale, usually by swapping the day and month values. That one has bitten me when I have had to use Excel. The solution I found was to always use international format (-mm-dd) as that didn't seem to be altered. Jim On 05/03/2014 06:56 AM, Bert Gunter wrote: ChangJiang: Open the .csv file with Notepad or other plain vanilla text processor, NOT EXCEL. You will find that the columns are text. Excel automatically converts them to dates. Read Excel's docs or get help from someone to learn how to convert the dates back to text. -- Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Fri, May 2, 2014 at 12:35 PM, ChangJiang Xu changjiang.h...@gmail.com wrote: Thanks. I still didn't get the solution. For example, I have a data frame, called temp temp Chr Ref Var AFFUNAFF AFF.test pvalue 1 10 A G 2/1/240/0/1905/49 2.429e-09 2 18 G A 1/9/17 0/23/167 11/43 2.484e-04 3 1 G A 2/2/220/8/176 6/46 4.293e-04 4 11 T G 1/1/250/2/188 3/51 1.193e-03 5 2 A T 1/10/16 38/90/60 12/42 2.220e-03 6 3 G A 1/16/10 8/49/13318/36 4.549e-03 Then I want to write a csv file using R function write.csv, as follows: write.csv(temp, file=temp.csv, row.names = FALSE) and the csv file, temp.csv, looks like the below, not same as original data ChrRefVarAFF UNAFFAFF.testpvalue 10AG02/01/20240/0/190May-492.43E-09 18GA01/09/20170/23/167 Nov-430.0002484 1 GA02/02/20220/8/176Jun-460.0004293 11 TG01/01/20250/2/188Mar-510.001193 2 AT01/10/201638/90/60 Dec-420.00222 3 GA1/16/108/49/133 18/36 0.004549 On Fri, May 2, 2014 at 3:06 PM, Bert Guntergunter.ber...@gene.com wrote: Read your Excel documentation. AFAIK, R just writes text files -- you need to tell Excel how to read them in. Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Fri, May 2, 2014 at 11:34 AM, ChangJiang Xu changjiang.h...@gmail.com wrote: By dafault, write.csv will change the characters such as 5/38 as a date May-38. How can I not change the format? Thanks. ChangJiang [[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. __ 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 fix the format in write.csv
Thanks. I still didn't get the solution. For example, I have a data frame, called temp temp Chr Ref Var AFFUNAFF AFF.test pvalue 1 10 A G 2/1/240/0/1905/49 2.429e-09 2 18 G A 1/9/17 0/23/167 11/43 2.484e-04 3 1 G A 2/2/220/8/176 6/46 4.293e-04 4 11 T G 1/1/250/2/188 3/51 1.193e-03 5 2 A T 1/10/16 38/90/60 12/42 2.220e-03 6 3 G A 1/16/10 8/49/13318/36 4.549e-03 Then I want to write a csv file using R function write.csv, as follows: write.csv(temp, file=temp.csv, row.names = FALSE) and the csv file, temp.csv, looks like the below, not same as original data ChrRefVarAFF UNAFFAFF.testpvalue 10AG02/01/20240/0/190May-492.43E-09 18GA01/09/20170/23/167 Nov-430.0002484 1 GA02/02/20220/8/176Jun-460.0004293 11 TG01/01/20250/2/188Mar-510.001193 2 AT01/10/201638/90/60 Dec-420.00222 3 GA1/16/108/49/133 18/36 0.004549 On Fri, May 2, 2014 at 3:06 PM, Bert Gunter gunter.ber...@gene.com wrote: Read your Excel documentation. AFAIK, R just writes text files -- you need to tell Excel how to read them in. Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Fri, May 2, 2014 at 11:34 AM, ChangJiang Xu changjiang.h...@gmail.com wrote: By dafault, write.csv will change the characters such as 5/38 as a date May-38. How can I not change the format? Thanks. ChangJiang [[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. [[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 fix the format in write.csv
Hi I second Jim's comments. I have also been bitten by British being converted to American format as well as ANSI numeric to a date format which I did not want . And if you want to take a daily series from the 1890's to the 2000's caveat emptor. If you are dealing with dates use something that will give you a proper output date format. Even beware of old versions of Access exporting excel files they are really html files. Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jim Lemon Sent: Saturday, 3 May 2014 07:21 To: Bert Gunter Cc: r-help@r-project.org Subject: Re: [R] How to fix the format in write.csv Hi ChangJiang, Date conversion is one of the biggest headaches with Excel. Even if you import those data into Excel and then specify that the column should be text format, it won't convert the values back into what they originally were. Be aware that Excel may, when encountering dates from a different locale, _silently_ convert the ones that aren't valid in its current locale, usually by swapping the day and month values. That one has bitten me when I have had to use Excel. The solution I found was to always use international format (-mm-dd) as that didn't seem to be altered. Jim On 05/03/2014 06:56 AM, Bert Gunter wrote: ChangJiang: Open the .csv file with Notepad or other plain vanilla text processor, NOT EXCEL. You will find that the columns are text. Excel automatically converts them to dates. Read Excel's docs or get help from someone to learn how to convert the dates back to text. -- Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Fri, May 2, 2014 at 12:35 PM, ChangJiang Xu changjiang.h...@gmail.com wrote: Thanks. I still didn't get the solution. For example, I have a data frame, called temp temp Chr Ref Var AFFUNAFF AFF.test pvalue 1 10 A G 2/1/240/0/1905/49 2.429e-09 2 18 G A 1/9/17 0/23/167 11/43 2.484e-04 3 1 G A 2/2/220/8/176 6/46 4.293e-04 4 11 T G 1/1/250/2/188 3/51 1.193e-03 5 2 A T 1/10/16 38/90/60 12/42 2.220e-03 6 3 G A 1/16/10 8/49/13318/36 4.549e-03 Then I want to write a csv file using R function write.csv, as follows: write.csv(temp, file=temp.csv, row.names = FALSE) and the csv file, temp.csv, looks like the below, not same as original data ChrRefVarAFF UNAFFAFF.testpvalue 10AG02/01/20240/0/190May-492.43E-09 18GA01/09/20170/23/167 Nov-430.0002484 1 GA02/02/20220/8/176Jun-460.0004293 11 TG01/01/20250/2/188Mar-510.001193 2 AT01/10/201638/90/60 Dec-420.00222 3 GA1/16/108/49/133 18/36 0.004549 On Fri, May 2, 2014 at 3:06 PM, Bert Guntergunter.ber...@gene.com wrote: Read your Excel documentation. AFAIK, R just writes text files -- you need to tell Excel how to read them in. Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Fri, May 2, 2014 at 11:34 AM, ChangJiang Xu changjiang.h...@gmail.com wrote: By dafault, write.csv will change the characters such as 5/38 as a date May-38. How can I not change the format? Thanks. ChangJiang [[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. __ 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.