How to export dataframe to RDATA file in R?
Last Updated :
25 Nov, 2023
In this, article we are going to save the information of a data frame in an RDATA file and display the information of the file using R Programming language. To save the information of a data frame in a file and display the information of the file in R language is as follows:
- Using the save function to save the file .RData format.
- Using the load() function to load that saved.RData file
- Using the file.info() function to get the information of a particular file.
Step 1: Use the save() function to save the file.RData format
In this step user needs to call the save(), function with the name of the new file and with its format passed as its parameter, This function will simply save the file as per the user-specified parameter in the working directory.
save() function: This function writes an external representation of R objects to the specified file.
Syntax: save(…, list = character(), file = stop(“‘file’ must be specified”),ascii = FALSE, version = NULL, envir = parent.frame(), compress = isTRUE(!ascii), compression_level, eval.promises = TRUE, precheck = TRUE)
In this example, we will be simply saving a data frame in new.RData file in the working directory.
R
gfg_data = data.frame (A = c (7,6,2,8,1),
B = c (4,2,9,7,3),
C = c (1,7,2,6,8))
print ( "Dataframe:->" )
print (gfg_data)
save (gfg_data, file = "gfg.RData" )
|
Output:
[1] "Dataframe:->"
A B C
1 7 4 1
2 6 2 7
3 2 9 2
4 8 7 6
5 1 3 8

Step 2: Use the load() function to load that saved.RData file
In this step user just need to call the load() function with the name of the file saved in step-1 as its parameter, further, this will help to load the save file in the console so that the user can manage the operation on this file.
Load() function: This function is used to reload datasets written with the function save.
Syntax: load(file, envir = parent.frame(), verbose = FALSE)
Parameters:
- File:-a character string giving the name of the file to load.
- envir:-the environment where the data should be loaded.
- Verbose:-should item name be printed during loading?needs
Under this example, we will be loading the.RData file using the load() function which was saved in the previous example.
Output:
A B C
1 7 4 1
2 6 2 7
3 2 9 2
4 8 7 6
5 1 3 8
Step3: Using file.info() function to get the information of a particular file.
This is the final step to save the information of a data frame in a file and displays its information, Here the step1 and step2 is used to save the information of the given data frame in a particular file and this step3 will be used to displaying the information of the file where the given data-frame is been saved and for this, we will be using the file.info() function with the name of the previously loaded file in the console to display the information of the file saved.
file.info() function: This is a utility function used to extract information about files on the user’s file systems.
Syntax: file.info(…, extra_cols = TRUE)
Parameter:
- …:-character vectors containing file paths
- extra_cols:-Logical: return all cols rather than just the first six.
Returns: size , isdir, mode, ctime, time, atime and exe
Using the file.info() function in R language we will be displaying the completed information of the file saved and loaded in the previous examples.
Output:
size isdir mode mtime ctime
gfg.RData 185 FALSE 666 2023-07-28 15:35:33 2023-07-28 15:29:53
atime exe
gfg.RData 2023-07-28 15:35:34 no
Similar Reads
How to export a DataFrame to Excel File in R ?
It is a frequent requirement to save our dataframe for portability after working on it on the auxiliary memory of the computer system using R Programming Language. In this article, we will be using writexl package to export our dataframe to excel(.xlsx). The write_xlsx() function of the writexl pack
3 min read
How to Export DataFrame to CSV in R ?
R Programming language allows us to read and write data into various files like CSV, Excel, XML, etc. In this article, we are going to discuss how to Export DataFrame to CSV file in R Programming Language. Approach: Write Data in column wise formatCreate DataFrame for these dataWrite Data to the CSV
1 min read
How to Delete DataFrames in R?
In R, a DataFrame is a data structure which can be two-dimensional, that is it can be used to hold data in rows and columns. To create a DataFrame, you can use the data.frame() function. but after you're done with a DataFrame, you may wish to remove it so that memory can be released or your workspac
3 min read
How To Export a Matrix as a CSV File in MATLAB?
A CSV file - Comma Separated File, as the name suggests, is a file that stores data delimited by a ' , '. In MATLAB, there is a simple way of exporting a matrix to a csv file. The writematrix() function is used to write a matrix into any desired file type. The syntax is writematrix(, "filename.exten
2 min read
R Read Text File to DataFrame
In today's data-driven world, collecting data from multiple sources and turning it into a structured manner is a critical responsibility for data analysts and scientists. Text files are a prominent source of data, as they frequently include useful information in plain text format. To be used success
5 min read
How to Write Entire Dataframe into MySQL Table in R
In this article, we are going to learn how to write the entire data frame into a MySQL table in R programming language. To perform this task we need some basic requirements which are listed below: Install MySQLInstall R StudioBasic knowledge of SQL queries. Using SQL queries create a database "gfg_d
3 min read
Write DataFrame to SPSS .sav File in R
In this article, we are going to see how to write Dataframe to SPSS .sav File in R Programming language. The SPSS Statistics File Format is a proprietary binary format, developed and maintained as the native format for the SPSS statistical software application. To write a data frame in SPSS format i
1 min read
How to Convert Numeric Dataframe to Text in xlsx File in R
In this article, we are going to convert a numeric data frame which means the data present in both rows and columns of the data frame is of numeric type to an Excel file(.xlsx). To achieve this mechanism in R Programming, we have a package called writexl which contains the write_xlsx() function whic
2 min read
Exporting a Pandas DataFrame to an Excel file
Sometimes we need an Excel file for reporting, so as a coder we will see how to export Pandas DataFrame to an Excel file. The to_excel() function in the Pandas library is utilized to export a DataFrame to an Excel sheet with the .xlsx extension. Syntax # saving the exceldataframe_name.to_excel(file_
4 min read
Export Plot to EPS File in R
An EPS file is a graphics file saved in the Encapsulated PostScript (EPS) file format. The EPS files may contain images, graphics, or even text. In this article, we will discuss how we export a plot to an EPS file using R programming language. Method 1 : Using setEPS() method The postscripts can be
2 min read