[R] Output levels of categorical data to Excel using with()

Marc Schwartz marc_schwartz at me.com
Thu Jun 19 18:58:57 CEST 2014

On Jun 18, 2014, at 11:31 PM, Daniel Schwartz <das2890 at gmail.com> wrote:

> I have coded qualitative data with many (20+) different codes from a survey
> in an excel file. I am using the with() function to output the codes so we
> know what's there. Is it possible to direct the output from with() to an
> excel file? If not, what's another function that has the same, er,
> functionality?! Thanks, R World!

It is not clear from your description, that the use of with() is really relevant here. with() is typically used as a convenience wrapper to be able to evaluate the names of data frame columns in the environment of the data frame, rather than having to repeat the 'DataFrameName$' prefix over and over.

To export data from R to Excel files, there are various options which are listed both in the R wiki:


and in the R Data Import/Export manual:


Worst case, you can use ?write.csv to dump the data to a CSV file, which can then be opened with Excel.

The option you may prefer will depend upon your operating system, how comfortable you may or may not be relative to installing additional software, do you want to create a new Excel file with each export or be able to append to existing worksheets and how you may want to structure or format the worksheet(s) in Excel.


Marc Schwartz

P.S. I have a cousin Daniel, but different gmail e-mail address.

More information about the R-help mailing list