How to Read rda file in R (with Example)

read RDA Files in R, R Project is linked to the RDA development files. An R Data File (RDA) is a file that contains R data.

R is a statistical computing and graphics language and environment with a GPL license.

What exactly is an RDA file?

The R Foundation is the most common source of RDA files. RDA is an abbreviation for R Data File.

RDA files are related to a previous version of the R programming language.

R is a programming language that allows users to perform statistical analysis and create graphs.

The R application uses RDA files to store statistical data such as functions and values that the User provides at the R prompt when the program initially starts up.

Only the earlier version of the R program makes use of the RDA extension. In later versions, the RDA file format was phased out in favor of the RDATA file format.

RDA files can be opened with the free RStudio tool for Windows, macOS, and Linux systems in addition to R.

Rdata files are those having a .rda extension.

Save & Load RDA Files

To save certain types of files in R, use the save() function.

save(data, file='data.rda')

In R, you can load various sorts of files with the load() function:

load(file='data.rda')

The following example demonstrates each of these functions.

Example: Save RDA files in R

Let’s create a data frame and make this example reproducible while using the set.seed function.

set.seed(123)

Create a data frame now.

data<- data.frame(x=rnorm(500),y=rnorm(500),z=rnorm(500))

Now we can view the first six rows

head(data)
           x           y           z
1 -0.56047565 -0.60189285 -0.99579872
2 -0.23017749 -0.99369859 -1.03995504
3  1.55870831  1.02678506 -0.01798024
4  0.07050839  0.75106130 -0.13217513
5  0.12928774 -1.50916654 -2.54934277
6  1.71506499 -0.09514745  1.04057346

To save this data frame to a .rda file, we can use the save() function:

The data frame file is stored in the current working directory by default. You can see the working directory based on the getwd() function.

Let’s display the current working directory

getwd()
[1] "D:/RStudio"

Now we can save the .rda file

save(data, file='data.rda')

Let’s say we want to remove the data frame from the current R environment using the rm() function.

Remove the current R environment’s data frame

rm(df)

If we look at our present environment in RStudio, we can see that there are no objects there.

The load() method may then be used to load the.rda file into the current R environment:

load(file='data.rda')
head(data)
           x           y           z
1 -0.56047565 -0.60189285 -0.99579872
2 -0.23017749 -0.99369859 -1.03995504
3  1.55870831  1.02678506 -0.01798024
4  0.07050839  0.75106130 -0.13217513
5  0.12928774 -1.50916654 -2.54934277
6  1.71506499 -0.09514745  1.04057346

In RStudio, we can observe that the current environment now contains the following data frame.

pipe operator in R-Simplify Your Code with %>% »

Subscribe to our newsletter!

[newsletter_form type=”minimal”]

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

8 + eight =