How to transport data from R to excel?

Asked

Viewed 19,992 times

8

I calculated a series of data in R and would like to know which command I should use to transport them to an excel spreadsheet.

4 answers

4


The command to be executed using the package xlsReadWrite must be:

library(xlsReadWrite)
write.xls(mydata, "c:/arquivo.xls") 

Or you can use one of the following Packages:

  1. Writexls
  2. xlsx
  • 1

    xlsReadWrite package was removed from CRAN. the response to the original post should not include the package.

  • Still the file exists and is available for download. Therefore, it is one of a few options listed in the answer. It’s up to the person who asked to choose the one that suits him.

2

Can use:

library(xlsx)
write.xlsx(nomeObjeto,file="nomeObjeto.xlsx")

2

The package Writexls can be useful. After installing the package, just type the following command:

WriteXLS("m", "n.xls")

Where m is the database you are working on in Excel and n the name of the article you want to export in xls.

With this package, you can edit some features of the exported file, such as headers and column width...

  • 2

    Hi, user7779, welcome to [en.so]. Please use a spell checker in your browser, this makes it easy for everyone, thank you.

1

Even using Excel I prefer to work with CSV files (text always!), which with proper formatting, open in Excel smoothly. To create the CSV files I like to use the write.table.

For the files to be opened in Excel in Portuguese correctly I use:

write.table(df, file='arquivo.csv', sep=';', dec=',', row.names=FALSE)

In order for the files to be opened in Excel in English correctly I use:

write.table(df, file='arquivo.csv', sep=',', dec='.', row.names=FALSE)

You can open the file directly in Excel by clicking on the file icon (at least in Windows). With the advantage that the file is portable to any other program and OS.

  • You can use their aliases: write.csv() for the American format and write.csv2() for the Brazilian format

  • I prefer to leave the commands explicit, otherwise this is like PHP code where you need to memorize a hundred functions with similar names.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.