Monday, June 17, 2013

Exporting lists to a usable file

If you have a lot of data stored in a list (e.g. output from some statistical test), sometimes you just want to export it to a text file to save it or print or whatever.

It can be difficult.

It doesnt have to be.

do this:

sink("/Users/Desktop/timothywiemken/output.txt")

function

sink()

run those three lines of code, where:
"/Users..." is the output location for the file (I put everything on my desktop and save it elsewhere later)

function is the actual function you want to run.  For example:  chisq.test(data$number_of_glasses, data$heavy_metal_music)

and

sink() closes down the sink function

This will export a text file with whatever name you want (here, output.txt) to your desktop (or whatever location you want).

The output file will contain all of the values typically printed in the R console window... This function just "sinks" that output to a text file.  It will be in the same format as in the console window.

Very useful!

No comments:

Post a Comment