Dear all, I have a data frame whose name is m1. I want to write this data frame in text file as output.I am using this code- write.table(m1, file = "kas.txt", append = FALSE,row.names=F,quote=F,sep="\t") When I am opening my kas.txt file,the column names are not coming exactly above the column. What should I do.Please help me. Thanking you, Warm Regards Vikas Bansal Msc Bioinformatics Kings College London
On Jul 5, 2011, at 1:17 PM, Bansal, Vikas wrote:> Dear all, > > I have a data frame whose name is m1. > I want to write this data frame in text file as output.I am using > this code- > > write.table(m1, file = "kas.txt", append = > FALSE,row.names=F,quote=F,sep="\t") > > When I am opening my kas.txt file,the column names are not coming > exactly above the column.The 'write' functions do not add spacing for alignment. Use print() and capture.output() ?capture.output -- David Winsemius, MD West Hartford, CT
Hi, On Tue, Jul 5, 2011 at 1:17 PM, Bansal, Vikas <vikas.bansal at kcl.ac.uk> wrote:> Dear all, > > I have a data frame whose name is m1. > I want to write this data frame in text file as output.I am using this code- > > write.table(m1, file = "kas.txt", append = FALSE,row.names=F,quote=F,sep="\t") > > When I am opening my kas.txt file,the column names are not coming exactly above the column. > What should I do.Please help me.You are writing a tab-delimited text file -- unless the width (number of characters) of all the elements of all of your columns is less than your tab width, then what you want will never happen. You can either set your "tab width" in your text editor that you're using to view the file to some insanely large number so you can make the above statement true, or you can do what David suggested ... Is the reason you are writing the file in text so that you can display it in some text editor at some later point, or do you actually want to use the data in other ways later? I also reckon if you open your tab-delimited file in something like excel, then all things should come out as "nice" as you want .. -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology ?| Memorial Sloan-Kettering Cancer Center ?| Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact
Use 'write.csv' and then use EXCEL as the way of formatting the output in the way that you like it. Otherwise you want use 'sprintf' to specify how you want the formatting done. On Tue, Jul 5, 2011 at 1:17 PM, Bansal, Vikas <vikas.bansal at kcl.ac.uk> wrote:> Dear all, > > I have a data frame whose name is m1. > I want to write this data frame in text file as output.I am using this code- > > write.table(m1, file = "kas.txt", append = FALSE,row.names=F,quote=F,sep="\t") > > When I am opening my kas.txt file,the column names are not coming exactly above the column. > What should I do.Please help me. > > > Thanking you, > Warm Regards > Vikas Bansal > Msc Bioinformatics > Kings College London > ______________________________________________ > R-help at 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 Data Munger Guru What is the problem that you are trying to solve?