[R] Problem in writing a R data frame to Excel format using RODBC package

Duncan Murdoch murdoch.duncan at gmail.com
Mon Aug 29 15:06:04 CEST 2011


On 29/08/2011 8:54 AM, Smart Guy wrote:
> Hi All,
>          Here is the short description of my problem.
> >mydata  ###my data.frame
> age   height   weight
> 12      97         30
> 14      95         32
> 17      120        50
>
> I used a following method from RODBC package. ver 1.3.1, to save as excel
> file.
>
> sqlSave(channel,* mydata*, tablename="Sheet1", *colnames = TRUE*)
>
> I got two header rows in Excel file:-
>
> age   height   weight
> age   height   weight
> 12      97         30
> 14      95         32
> 17      120        50
>
> I need one row if parameter *colnames = TRUE* and no header rows if *
> colnames=FALSE*. And actually it should work like this.

As the help page says, colnames=TRUE adds the column names as the first 
row of data.  They also appear as column names.  So you see them twice.

Complain to Microsoft (or Dan Bricklin) if you don't like the fact that 
you can't distinguish between column names and data in a spreadsheet.

Duncan Murdoch

> If any one came across same issue, kindly help me.
>
> -Thanks
> SmartG
>
>
> On 29 August 2011 16:14, Smart Guy<smartguy3k at gmail.com>  wrote:
>
> >  Hi Experts,
> >                I was trying to write a data frame which has a header row,
> >  from R to Excel disk file using RODBC ( RODBC_1.3-1) package. I met with an
> >  issue:-  If in sqlSave(), I set  a parameter "colnames=FALSE" then I get
> >  first row as header in excel file. If 'colnames=TRUE' then it gives me first
> >  2 rows as header in excel file.
> >              Actually, according to my understanding, for FALSE it should
> >  not write header row to Excel file and for TRUE it should write a single
> >  header row to Excel.
> >  Data is ok. Problem is with header row.
> >
> >  sqlSave() is in RODBC package.
> >
> >  Kindly, suggest something. I need an option so that whenever I want I can
> >  save header to excel file or else drop the header and can only save data to
> >  Excel.
> >
> >  Thanks and Regards
> >  SmartG
> >
>
>
>



More information about the R-help mailing list