[R] re ad.table prn file
Dear Forum, I´ve imported a prn file with read.table (file(E:/test.prn),sep=\t,skip=3). My problem is now, that my file has a complicated structure: It is not tabstop seperated, it looks like that: JEAR JAN FEB MAR APR 1938154 912 19396 71014 19409 If there are default values, there is no seperation in the line, I want that the program seperates after every JAN, FEB (in detail after the 18., 24., 36 character). Is there a possibility to seperate after i.e.the 15. character? i tried with strsplit, but get no satisfying result. Please help me. I think I could do this with exel and export it with csv, but i would like to solve the problem with R. -- View this message in context: http://www.nabble.com/read.table-prn-file-tp22161342p22161342.html Sent from the R help mailing list archive at Nabble.com. __ 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] re ad.table prn file
On Mon, Feb 23, 2009 at 05:18:28AM -0800, canadiangirl19 wrote: My problem is now, that my file has a complicated structure: It is not tabstop seperated, it looks like that: JEAR JAN FEB MAR APR 1938154 912 19396 71014 19409 If there are default values, there is no seperation in the line, I want that the program seperates after every JAN, FEB (in detail after the 18., 24., 36 character). Is there a possibility to seperate after i.e.the 15. character? i tried with strsplit, but get no satisfying result. Sounds like read.fwf may solve your problem. cu Philipp -- Dr. Philipp Pagel Lehrstuhl für Genomorientierte Bioinformatik Technische Universität München Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://mips.gsf.de/staff/pagel __ 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] re ad.table prn file
I´ve tried with: write.fwf(test,file=E:/test.prn,widths=6), but get the error: Fehler in write.table(t(as.matrix(colnamesMy)), file = file, append = append, : unbenutzte(s) Argument(e) (widths = 6) My matrix hast only one column (so it is a vector), and many rows, I want to seperate the vector (after 6 character, I don´t know, is the width=6?) in a matrix with 5 columns. How can I do this? And with format.info I get no output. thanks in advance for helping me Philipp Pagel-5 wrote: On Mon, Feb 23, 2009 at 05:18:28AM -0800, canadiangirl19 wrote: My problem is now, that my file has a complicated structure: It is not tabstop seperated, it looks like that: JEAR JAN FEB MAR APR 1938154 912 19396 71014 19409 If there are default values, there is no seperation in the line, I want that the program seperates after every JAN, FEB (in detail after the 18., 24., 36 character). Is there a possibility to seperate after i.e.the 15. character? i tried with strsplit, but get no satisfying result. Sounds like read.fwf may solve your problem. cu Philipp -- Dr. Philipp Pagel Lehrstuhl für Genomorientierte Bioinformatik Technische Universität München Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://mips.gsf.de/staff/pagel __ 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. -- View this message in context: http://www.nabble.com/read.table-prn-file-tp22161342p22162335.html Sent from the R help mailing list archive at Nabble.com. __ 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] re ad.table prn file
On Mon, Feb 23, 2009 at 06:24:33AM -0800, canadiangirl19 wrote: write.fwf(test,file=E:/test.prn,widths=6), but get the error: Fehler in write.table(t(as.matrix(colnamesMy)), file = file, append = append, : unbenutzte(s) Argument(e) (widths = 6) My matrix hast only one column (so it is a vector), and many rows, I want to seperate the vector (after 6 character, I don´t know, is the width=6?) in a matrix with 5 columns. How can I do this? And with format.info I get no output. Are you sure the above is your actual code? I didn't even know the function write.fwf existed. I was suggesting was to READ the file with read.fwf. Your reply seems to indicate that you are first reading the file by some other means and then trying to write it back to a file. If, for some obscure reason, you really cannot use read.fwf(), textConnection() would be an option. But it would probably only complicate things more than necessary. cu Philipp -- Dr. Philipp Pagel Lehrstuhl für Genomorientierte Bioinformatik Technische Universität München Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://mips.gsf.de/staff/pagel __ 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] re ad.table prn file
It works thanks a lot Philipp Pagel-5 wrote: On Mon, Feb 23, 2009 at 06:24:33AM -0800, canadiangirl19 wrote: write.fwf(test,file=E:/test.prn,widths=6), but get the error: Fehler in write.table(t(as.matrix(colnamesMy)), file = file, append = append, : unbenutzte(s) Argument(e) (widths = 6) My matrix hast only one column (so it is a vector), and many rows, I want to seperate the vector (after 6 character, I don´t know, is the width=6?) in a matrix with 5 columns. How can I do this? And with format.info I get no output. Are you sure the above is your actual code? I didn't even know the function write.fwf existed. I was suggesting was to READ the file with read.fwf. Your reply seems to indicate that you are first reading the file by some other means and then trying to write it back to a file. If, for some obscure reason, you really cannot use read.fwf(), textConnection() would be an option. But it would probably only complicate things more than necessary. cu Philipp -- Dr. Philipp Pagel Lehrstuhl für Genomorientierte Bioinformatik Technische Universität München Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://mips.gsf.de/staff/pagel __ 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. -- View this message in context: http://www.nabble.com/read.table-prn-file-tp22161342p22176814.html Sent from the R help mailing list archive at Nabble.com. __ 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.