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.
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/
Jorge Ivan Velez
2010-Sep-08 01:48 UTC
[R] how to you output a vector to a column in excel?
Try vector <- c(1,2,3,4) write.table(data.frame(vector), "example.xls", col.names = TRUE, row.names FALSE) See ?write.table for more information. HTH, Jorge On Tue, Sep 7, 2010 at 5:33 PM, lord12 <> 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@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. >[[alternative HTML version deleted]]
If you have Excel running with the sheet that you want to use open, then in R you can just do:> write.table( 1:10, 'clipboard', sep='\t', row.names=FALSE, col.names=FALSE ) >(replace 1:10 with your vector) Then go to excel, right click on the cell where you want the first number to be, and select paste. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of lord12 > Sent: Tuesday, September 07, 2010 3:33 PM > To: r-help at r-project.org > Subject: [R] how to you output a vector to a column in excel? > > > 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.
What happens if I want to automate this process for say 500 vectors? -- View this message in context: http://r.789695.n4.nabble.com/how-to-you-output-a-vector-to-a-column-in-excel-tp2530470p2536402.html Sent from the R help mailing list archive at Nabble.com.
Well that depends which process you are automating, how your vectors are stored, and where you want them going. Do you want 500 Excel spreadsheets with each vector in Column A? Do you want 1 spreadsheet with each vector appended below the previous? Do you want 1 spreadsheet with each vector in the next column (like a table)? Are these vectors all stored in a list or just in the workspace? Do they have names that can be readily recreated or do their names all have to be typed out? Josh On Sun, Sep 12, 2010 at 8:14 AM, lord12 <gaut222 at yahoo.com> wrote:> > What happens if I want to automate this process for say 500 vectors? > -- > View this message in context: http://r.789695.n4.nabble.com/how-to-you-output-a-vector-to-a-column-in-excel-tp2530470p2536402.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/