[R] Fw: Re: Is there anything like a write.fwf() or possibility to print adata.frame without rownames?
Petr Pikal wrote: Hi did you tried something like write.table( tab, file.txt, sep=\t, row.names=F) which writes to tab separated file? Petr thanks, but I do not want a tab delimited file. I need spaces between columns. write.table( tab, file.txt, sep=, row.names=F) Can it do what you want? Ronggui thanks, but this does not work also. For example I get something like this bellow 26 1 42 DA DA lipa Monika 26 1 42 DA DA lipa Monika 27 1 41 DA DA smreka Monika 27 1 41 DA DA smreka Monika and you can see, that there is a problem, when all values in a column do not have the same length. I need to get 26 1 42 DA DA lipa Monika 26 1 42 DA DA lipa Monika 27 1 41 DA DA smreka Monika 27 1 41 DA DA smreka Monika i.e. columns should be properly aligned. Lep pozdrav / With regards, Gregor Gorjanc -- University of Ljubljana Biotechnical FacultyURI: http://www.bfro.uni-lj.si/MR/ggorjan Zootechnical Department mail: gregor.gorjanc at bfro.uni-lj.si Groblje 3 tel: +386 (0)1 72 17 861 SI-1230 Domzale fax: +386 (0)1 72 17 888 Slovenia, Europe -- One must learn by doing the thing; for though you think you know it, you have no certainty until you try. Sophocles ~ 450 B.C. __ R-help@stat.math.ethz.ch 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] Fw: Re: Is there anything like a write.fwf() or possibility to print adata.frame without rownames?
Hi can you please explain why do you need it? What do you want to do with the exported file? I wonder what type of software can not accept any reasonable delimiter and requires fwf files. The only workaround I can imagine is to transfer all columns to character and add leading spaces to each item which is shorter than longest item in specified column to equalize length of all items in column and then use write.table( tab, file.txt, sep= , row.names=F) as suggested. But I still wonder why? If you used e.g. write.table( tab, file.xls, sep=\t, row.names=F) you can open it directly by spreadsheet program just by clickung on it and everything shall be properly aligned. HTH Petr On 22 Nov 2005 at 12:26, Gorjanc Gregor wrote: Date sent:Tue, 22 Nov 2005 12:26:43 +0100 From: Gorjanc Gregor [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Copies to:[EMAIL PROTECTED] Subject: [R] Fw: Re: Is there anything like a write.fwf() or possibility to print adata.frame without rownames? Petr Pikal wrote: Hi did you tried something like write.table( tab, file.txt, sep=\t, row.names=F) which writes to tab separated file? Petr thanks, but I do not want a tab delimited file. I need spaces between columns. write.table( tab, file.txt, sep=, row.names=F) Can it do what you want? Ronggui thanks, but this does not work also. For example I get something like this bellow 26 1 42 DA DA lipa Monika 26 1 42 DA DA lipa Monika 27 1 41 DA DA smreka Monika 27 1 41 DA DA smreka Monika and you can see, that there is a problem, when all values in a column do not have the same length. I need to get 26 1 42 DA DA lipa Monika 26 1 42 DA DA lipa Monika 27 1 41 DA DA smreka Monika 27 1 41 DA DA smreka Monika i.e. columns should be properly aligned. Lep pozdrav / With regards, Gregor Gorjanc -- University of Ljubljana Biotechnical FacultyURI: http://www.bfro.uni-lj.si/MR/ggorjanZootechnical Department mail: gregor.gorjanc at bfro.uni-lj.si Groblje 3 tel: +386 (0)1 72 17 861 SI-1230 Domzale fax: +386 (0)1 72 17 888 Slovenia, Europe -- One must learn by doing the thing; for though you think you know it, you have no certainty until you try. Sophocles ~ 450 B.C. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Petr Pikal [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch 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] Fw: Re: Is there anything like a write.fwf() or possibility to print adata.frame without rownames?
Hi can you please explain why do you need it? What do you want to do with the exported file? I wonder what type of software can not accept any reasonable delimiter and requires fwf files. The only workaround I can imagine is to transfer all columns to character and add leading spaces to each item which is shorter than longest item in specified column to equalize length of all items in column and then use write.table( tab, file.txt, sep= , row.names=F) as suggested. But I still wonder why? OK, I did not want to be to specific, but here it goes. I am using some special software for variance component estimation and prediction in genetics. Programs are VCE and PEST (http://w3.tzv.fal.de/%7Eeg/) and they both read data in FW (fixed width) format. For those programs you can only give data in such format and it is really tedious to do so, but that is the way it is. If you used e.g. write.table( tab, file.xls, sep=\t, row.names=F) you can open it directly by spreadsheet program just by clickung on it and everything shall be properly aligned. I am fully aware of this, but I do need FW format. I will try with sprintf(), but this looks very though for me. Petr Pikal wrote: Hi did you tried something like write.table( tab, file.txt, sep=\t, row.names=F) which writes to tab separated file? Petr thanks, but I do not want a tab delimited file. I need spaces between columns. write.table( tab, file.txt, sep=, row.names=F) Can it do what you want? Ronggui thanks, but this does not work also. For example I get something like this bellow 26 1 42 DA DA lipa Monika 26 1 42 DA DA lipa Monika 27 1 41 DA DA smreka Monika 27 1 41 DA DA smreka Monika and you can see, that there is a problem, when all values in a column do not have the same length. I need to get 26 1 42 DA DA lipa Monika 26 1 42 DA DA lipa Monika 27 1 41 DA DA smreka Monika 27 1 41 DA DA smreka Monika i.e. columns should be properly aligned. Lep pozdrav / With regards, Gregor Gorjanc -- University of Ljubljana Biotechnical FacultyURI: http://www.bfro.uni-lj.si/MR/ggorjan Zootechnical Department mail: gregor.gorjanc at bfro.uni-lj.si Groblje 3 tel: +386 (0)1 72 17 861 SI-1230 Domzale fax: +386 (0)1 72 17 888 Slovenia, Europe -- One must learn by doing the thing; for though you think you know it, you have no certainty until you try. Sophocles ~ 450 B.C. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Petr Pikal [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch 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] Fw: Re: Is there anything like a write.fwf() or possibility to print adata.frame without rownames?
On 11/22/05, Gorjanc Gregor [EMAIL PROTECTED] wrote: Hi can you please explain why do you need it? What do you want to do with the exported file? I wonder what type of software can not accept any reasonable delimiter and requires fwf files. The only workaround I can imagine is to transfer all columns to character and add leading spaces to each item which is shorter than longest item in specified column to equalize length of all items in column and then use write.table( tab, file.txt, sep= , row.names=F) as suggested. But I still wonder why? OK, I did not want to be to specific, but here it goes. I am using some special software for variance component estimation and prediction in genetics. Programs are VCE and PEST (http://w3.tzv.fal.de/%7Eeg/) and they both read data in FW (fixed width) format. For those programs you can only give data in such format and it is really tedious to do so, but that is the way it is. If you used e.g. write.table( tab, file.xls, sep=\t, row.names=F) you can open it directly by spreadsheet program just by clickung on it and everything shall be properly aligned. I am fully aware of this, but I do need FW format. I will try with sprintf(), but this looks very though for me. Petr Pikal wrote: Hi did you tried something like write.table( tab, file.txt, sep=\t, row.names=F) which writes to tab separated file? Petr thanks, but I do not want a tab delimited file. I need spaces between columns. write.table( tab, file.txt, sep=, row.names=F) Can it do what you want? Ronggui thanks, but this does not work also. For example I get something like this bellow 26 1 42 DA DA lipa Monika 26 1 42 DA DA lipa Monika 27 1 41 DA DA smreka Monika 27 1 41 DA DA smreka Monika and you can see, that there is a problem, when all values in a column do not have the same length. I need to get 26 1 42 DA DA lipa Monika 26 1 42 DA DA lipa Monika 27 1 41 DA DA smreka Monika 27 1 41 DA DA smreka Monika i.e. columns should be properly aligned. Try this: irish - head(iris) write(t(apply(irish, 2, format)), file = , ncol = ncol(irish)) 5.1 3.5 1.4 0.2 setosa 4.9 3.0 1.4 0.2 setosa 4.7 3.2 1.3 0.2 setosa 4.6 3.1 1.5 0.2 setosa 5.0 3.6 1.4 0.2 setosa 5.4 3.9 1.7 0.4 setosa __ R-help@stat.math.ethz.ch 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] Fw: Re: Is there anything like a write.fwf() or possibility to print adata.frame without rownames?
Why don't you just use 'sprintf' and set the format up to what you want: x - head(iris) cat(sprintf(%6.1f%6.1f%6.1f%6.1f %-20s\n, x[,1], x[,2], x[,3], x[,4], x[,5]), sep='') 5.1 3.5 1.4 0.2 setosa 4.9 3.0 1.4 0.2 setosa 4.7 3.2 1.3 0.2 setosa 4.6 3.1 1.5 0.2 setosa 5.0 3.6 1.4 0.2 setosa 5.4 3.9 1.7 0.4 setosa On 11/22/05, Gabor Grothendieck [EMAIL PROTECTED] wrote: On 11/22/05, Gorjanc Gregor [EMAIL PROTECTED] wrote: Hi can you please explain why do you need it? What do you want to do with the exported file? I wonder what type of software can not accept any reasonable delimiter and requires fwf files. The only workaround I can imagine is to transfer all columns to character and add leading spaces to each item which is shorter than longest item in specified column to equalize length of all items in column and then use write.table( tab, file.txt, sep= , row.names=F) as suggested. But I still wonder why? OK, I did not want to be to specific, but here it goes. I am using some special software for variance component estimation and prediction in genetics. Programs are VCE and PEST (http://w3.tzv.fal.de/%7Eeg/) and they both read data in FW (fixed width) format. For those programs you can only give data in such format and it is really tedious to do so, but that is the way it is. If you used e.g. write.table( tab, file.xls, sep=\t, row.names=F) you can open it directly by spreadsheet program just by clickung on it and everything shall be properly aligned. I am fully aware of this, but I do need FW format. I will try with sprintf(), but this looks very though for me. Petr Pikal wrote: Hi did you tried something like write.table( tab, file.txt, sep=\t, row.names=F) which writes to tab separated file? Petr thanks, but I do not want a tab delimited file. I need spaces between columns. write.table( tab, file.txt, sep=, row.names=F) Can it do what you want? Ronggui thanks, but this does not work also. For example I get something like this bellow 26 1 42 DA DA lipa Monika 26 1 42 DA DA lipa Monika 27 1 41 DA DA smreka Monika 27 1 41 DA DA smreka Monika and you can see, that there is a problem, when all values in a column do not have the same length. I need to get 26 1 42 DA DA lipa Monika 26 1 42 DA DA lipa Monika 27 1 41 DA DA smreka Monika 27 1 41 DA DA smreka Monika i.e. columns should be properly aligned. Try this: irish - head(iris) write(t(apply(irish, 2, format)), file = , ncol = ncol(irish)) 5.1 3.5 1.4 0.2 setosa 4.9 3.0 1.4 0.2 setosa 4.7 3.2 1.3 0.2 setosa 4.6 3.1 1.5 0.2 setosa 5.0 3.6 1.4 0.2 setosa 5.4 3.9 1.7 0.4 setosa __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Jim Holtman Cincinnati, OH +1 513 247 0281 What the problem you are trying to solve? [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] Fw: Re: Is there anything like a write.fwf() or possibility to print adata.frame without rownames?
If you are desperate, save the file as tab delimited and then use vi or some stream editor to convert the tabs to spaces. If you set the tab stop wide enough you should be able to guarantee uniform columns. Gorjanc Gregor wrote: Petr Pikal wrote: Hi did you tried something like write.table( tab, file.txt, sep=\t, row.names=F) which writes to tab separated file? Petr thanks, but I do not want a tab delimited file. I need spaces between columns. write.table( tab, file.txt, sep=, row.names=F) Can it do what you want? Ronggui thanks, but this does not work also. For example I get something like this bellow 26 1 42 DA DA lipa Monika 26 1 42 DA DA lipa Monika 27 1 41 DA DA smreka Monika 27 1 41 DA DA smreka Monika and you can see, that there is a problem, when all values in a column do not have the same length. I need to get 26 1 42 DA DA lipa Monika 26 1 42 DA DA lipa Monika 27 1 41 DA DA smreka Monika 27 1 41 DA DA smreka Monika i.e. columns should be properly aligned. Lep pozdrav / With regards, Gregor Gorjanc -- University of Ljubljana Biotechnical FacultyURI: http://www.bfro.uni-lj.si/MR/ggorjan Zootechnical Department mail: gregor.gorjanc at bfro.uni-lj.si Groblje 3 tel: +386 (0)1 72 17 861 SI-1230 Domzale fax: +386 (0)1 72 17 888 Slovenia, Europe -- One must learn by doing the thing; for though you think you know it, you have no certainty until you try. Sophocles ~ 450 B.C. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Fw: Re: Is there anything like a write.fwf() or possibility to print adata.frame without rownames?
Petr Pikal wrote: Hi did you tried something like write.table( tab, file.txt, sep=\t, row.names=F) which writes to tab separated file? Petr thanks, but I do not want a tab delimited file. I need spaces between columns. write.table( tab, file.txt, sep=, row.names=F) Can it do what you want? On 21 Nov 2005 at 11:56, Gregor Gorjanc wrote: Date sent: Mon, 21 Nov 2005 11:56:48 +0100 From:Gregor Gorjanc [EMAIL PROTECTED] Organization:University of Ljubljana To: [EMAIL PROTECTED] Subject: [R] Is there anything like a write.fwf() or possibility to print a data.frame without rownames? Send reply to: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] Dear R users, R has read.fwf() function, however I would need write.fwf. I know other write.* functions, but I need fixed width format of data, which I would like to export from R. I tried to use: - write.table, but I can not control alignment of columns - write.matrix from MASS, but columns are to wide I came to this option, which is very neat: # tmp is data.frame sink(file = file) print(tmp) sink() This works very nice, but I would like to get rid of rownames, which are always printed. Another not so important issue is width of printed columns. I presume this is determined by max(length column name, max(length of values in a column)) but sometimes it would be usefull to control width of columns also. Can someone help me with this issue? -- Lep pozdrav / With regards, Gregor Gorjanc -- University of Ljubljana PhD student Biotechnical Faculty Zootechnical Department URI: http://www.bfro.uni-lj.si/MR/ggorjan Groblje 3 mail: gregor.gorjanc at bfro.uni-lj.si SI-1230 Domzale tel: +386 (0)1 72 17 861 Slovenia, Europefax: +386 (0)1 72 17 888 -- One must learn by doing the thing; for though you think you know it, you have no certainty until you try. Sophocles ~ 450 B.C. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html = = = = = = = = = = = = = = = = = = = = 2005-11-21 -- Deparment of Sociology Fudan University My new mail addres is [EMAIL PROTECTED] Blog:http://sociology.yculblog.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html