banner



How To Export A Data Set From R

Importing information in R is surely of import for the user. However, exporting data from R to other platforms is equally important as well. You may want to export the data from R workspace into an excel file, or a CSV, or a Text file, or a PDF (in case you lot are creating a fancy report that needs to be sent to your dominate). Information technology is as straightforward to export information from R every bit information technology is to import information technology into R.

Through this article, we will walk through the processes and steps involved in exporting the data from R workspace to other platforms . Nosotros volition likewise try to cover unlike functions from packages such as readr and xlsx that are associated with the different format options for the excel files .

Through this commodity, we will walk you through how to export files from R to -

  • Exporting into Text/CSV

  • Exporting into Excel

  • Exporting into R Objects/R data files

Well, if yous haven't gone through yet, we would like you to read our commodity on Importing Data into R.

Exporting Data into Text/CSV

Well, exporting data into a text or a CSV file, is the well-nigh pop and indeed common way of data consign. Not only because near of the software supports the option to consign data into Text or CSV simply also because these files are supported by almost every software/programming language that exists.

There are two ways of exporting data into text files through R. One is using the base R functions and some other one is using the functions from the readr parcel to consign data into text/CSV format.

Using Built-in Functions

In that location is a popular built-in R function named write.table() which can practise the task of exporting the data into text files from R workspace. The part has two other special cases namely write.csv() and write.delim() out of which the outset one helps to export the data into CSV format and the second one is adjusted way of write.table() where default delimiters can be adjusted.

Let us come across an example here which will articulate the air out nigh these functions. Offset of all, permit us create a data frame that we would love to consign into a text/CSV file.


Creating a data frame which can be exported as a text file.

Creating a data frame to export



To consign this data frame into a CSV file, we tin employ the write.csv() role. See the example beneath:


This code shows how to export the data from R Workspace into csv with different options.

Exporting data from R into CSV


In this case, y'all could see the write.csv() function exports the data frame into a new CSV file named "d_frame_export". The thing you should go along in listen is about the file extension. You need to add together the .csv extension for this file to be exported equally a CSV file. The file gets stored at the default working directory.

You lot can also store this file at a location of your choice. Which is what exactly we did in the second instance in the code to a higher place. The third example emphasises the use of additional arguments that can be used under the write.csv() function. Ex. row.names = Simulated will allow you to eliminate the row names from the exported data file. We tin export this data frame equally a text file using write.table() function.


This image shows how the write.table() function allows you to export the data into a delimited text file.

Exporting data into a text file


Using Functions from readr Package

The functions under the readr package are similar to the functions available under base of operations R. There is a minor divergence in their look (write.csv() from base R and write_csv() from readr do the same stuff). Too the functions developed under the readr packet are using path = argument instead of file = to specify the path where the file needs to export. The functions from the readr package exclude the row names past default.

Also, the most of import advantages for the functions from readr parcel is, they are two times faster when it comes to the execution of the functions. See an instance below where nosotros try to export the aforementioned data frame into CSV and text file using functions built under readr parcel.


This image shows how the functions from the readr package work to export a data file into csv, and text file.

Exporting data into CSV/text file using functions from the readr package


This lawmaking shows different means of exporting the data into either CSV or text file using multiple alternatives. The UTF-8 is a special type of CSV file which has a different format than the usual CSV file and the excel recognizes such file. It is a CSV file with a bit of different formatting.

Exporting Data into Excel

At present, to consign data into Excel from R workspace, the best bait you could put on is the writexl parcel. This parcel allows y'all to export information every bit an Excel file into xlsx format. Information technology may exist looking outdated at this moment only believe me, the functions do their job with precision. Also, we always have the compatibility of new excel to be able to connect with the older versions.

Run into code below that explains how to export the data into an excel file using functions from the writexl packet.


This image shows the code which allows you to export the data frame into an excel file using functions from writexl package.

Exporting information frame into excel files using functions from writexl package


Now, here if you encounter, the functions from writexl packages are similar with those from the xlsx packages with only difference in their looks (xlsx package have write.xlsx() and here nosotros accept write_xlsx()).

Moreover, as shown in the previous example the write_excel_csv() role allows you to store a file into UTF-8 encoded CSV file which is recognized past Microsoft Excel. This gives us some other mode to export our data into excel format.

Well, one thing to note here is, before starting to utilize the packages yous should install them first into your workspace. Our article on Importing Data into R volition help you understand how to import information into your workspace and how to access the same.

Exporting Data into R Objects

There might come situations where you wanted to share the data from R as Objects and share those with your colleagues through different systems then that they can use it correct away into their R workspace. These objects are of two types .rda/.RData and .rds.

The .rda and.RData is similar and they tin can be used to store some or all objects, functions from your global environment. Whereas when y'all want to store single objects from your workspace (data frame, a newly developed statistical model), information technology is amend to use the .rds file. Well, you can also use the.RData, .rda to save the unmarried objects.

Only the .rds has real benefit lying within the fact that it allows you lot to store the object with a name and yous tin can assign the same to another object using assignment operator and access. On the other hand when you lot salve a file as.RData or .rda, it stores the object and its name equally well which means yous can't access a single object with a different alias.

Let'southward come across some examples of exporting data into R Objects.


This image shows different ways of exporting data into an R object.

Exporting data as an R Object


Summary

  • Exporting data is every bit important as importing the information into R workspace

  • To import information into csv, we tin use the built-in R functions such as write.tabular array(), write.csv() or a more than faster and simplified readr bundle which has functions such every bit write_csv(), write_delim()

  • Functions from readr bundle are twice speedy when it comes towards the execution speed.

  • The functions from readr package too exclude the row names for a data frame past default.

  • You lot can export a file at a different location by specifying the path to these functions. Moreover, you tin can store the text files with different delimiters.

  • Writexl parcel provides some useful functions that can help y'all export data into an excel file from R workspace.

  • R data objects can exist important to export your data to when you lot accept to share it with your colleagues or the user and so that they can employ it in their R Workspace. (Visit our exclusive department "R Programming" to acquire prime functions in R)

This article ends here. We will come up up with a new and interesting article on this list for you. Until so, Stay safe!

Source: https://analyticssteps.com/blogs/exporting-data-r

0 Response to "How To Export A Data Set From R"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel