[R] how to you output a vector to a column in excel?

Joshua Wiley jwiley.psych at gmail.com
Wed Sep 8 01:38:50 CEST 2010


Hi,

What *exactly* do you mean when you say "output"?  You can write the
vector to a .csv file which can easily be read by Excel using
write.csv() or more generally write.table() with the appropriate
arguments.  There is no way (that I know of) in base R to write .xls
or .xlsx files, but you can use the WriteXLS or RExcelInstaller
packages to write the .xls files.

If you are meaning export a vector to an existing, open Excel
spreadsheet, I suspect the process will be more difficult (although I
believe there are some packages/programs that try to integrate R with
Excel).

However, in general I would say the easiest way to exchange data
between R and Excel (and numerous other programs) is via write.table()
or write.csv().  Excel, SAS, SPSS, and others can read text files that
are tab, comma, etc. delimited so this is a more universal way of
exchanging data.  By default in Excel, the first column of a file will
be column A, so if you wanted your vector in column A, just save it as
a .csv, and open it in Excel and it will be there.  If you wanted the
vector in column C (in Excel), you would need to add some blank
columns as filler (when using write.csv() ).

HTH,

Josh

On Tue, Sep 7, 2010 at 2:33 PM, lord12 <gaut222 at yahoo.com> wrote:
>
> What is the syntax for this?
>
> If you have: vector = c(1,2,3,4), how would you output this to column A of
> an excel spreadsheet?
> --
> View this message in context: http://r.789695.n4.nabble.com/how-to-you-output-a-vector-to-a-column-in-excel-tp2530470p2530470.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list