Welcome to the Genome Toolbox! I am glad you navigated to the blog and hope you find the contents useful and insightful for your genomic needs. If you find any of the entries particularly helpful, be sure to click the +1 button on the bottom of the post and share with your colleagues. Your input is encouraged, so if you have comments or are aware of more efficient tools not included in a post, I would love to hear from you. Enjoy your time browsing through the Toolbox.
Showing posts with label format. Show all posts
Showing posts with label format. Show all posts

Monday, January 27, 2014

Produce SAS Proc Freq Output in R

I have never been a huge fan or advocate of SAS, and actually recommend using other SAS alternatives, but I am somewhat addicted to the SAS Proc Freq procedure and its output tables.  Its a nice way to not only visualize the data but also to get some useful summary statistics.  I have been using the R table command for a while and in most cases combined with margin.table or prop.table it suffices to summarize the data.  Recently, I have been in need of summary statistics for the tables as well.  This can be accomplished easy enough using the R chisq.test or fisher.test commands, but still doesn't quite provide the fluid integration of data visualization and summary statistics that the SAS Proc Freq output provides.  Today I came across the R package CrossTable.  This procedure, part of the gmodels library, provides formatted output very similar to that of Proc Freq.  So much so, it even uses the same ascii characters to delineate cell boundaries.  There is a bit of playing around with options and such to get the exact statistics and percentages and such you would like, but overall a very nice (a not to mention free) alternative to SAS's Proc Freq output.  Below is an example table I created.

Thursday, January 23, 2014

Formatting Excel Cells with Zero Filling

While Microsoft Excel could use some improvements for data management and analysis, it remains my program of choice for putting together summary tables, particularly the descriptive statistics of most Table 1's.  I'm pretty particular with formatting and wanted to create a Table 1 with column percentages that all lined up nicely.  To do this I needed to zero fill numbers both before and after the decimal point so that each number, when formatted, took up the same amount of space in the column.  I the past I would do this by pasting the table as text (without formulas) and then manually filling in zeros.  This was tedious, especially when having to redo tables after sample numbers changed.

Today I found out there is a way to have Excel automatically include these zeros.  You can do this by creating a custom number format.  Here's how to do so.

1). Right click on the cell you want to format and choose Format Cells...
2). Click the Number tab and select Custom in the Category: list.
3). Put in your desired formatting.  You can do this by building off other format types.  In my case, I wanted to have a format so that the numbers 3.5562 and 55 appeared as (03.6) and (55.0), respectively.  To do this the Type: box needed to have the format (00.0).  This will zero fill both before and after the decimal point as well as round all numbers by one decimal place.

As you can imagine, you can customize this to zero fill based on your particular needs or desired format type.  Below is an example Table 1 excerpt to show how the formatting looks.