Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in R Programming by (5.3k points)
edited by

I made a data.frame in R that is not very big, but it takes quite some time to build. I would like to save it as a file, which I can then again open in R?

2 Answers

+2 votes
by
edited

To save a data frame to a file in R, use the save() function from the base package as follows:

save(data_frame,file="DFrame.Rda")

This file will be saved in your current working directory.

To print the current working directory:

print(getwd())

To set the working directory:

setwd("Path")

To load the saved data frame:

load("Dframe.Rda")

If you want to learn more about R programming watch this tutorial on Introduction to Data Science with R 

0 votes
by (106k points)

Let’s suppose your DataFrame is named as df so you can write the CSV file as follows:

write.csv(df,file="exmp.csv")

After the above step you can load the CSV file easily:

read.csv(file="exmp.csv")

An alternate method for this is will be as follows:

save(df,file="data.Rda")

You can load the dataframe by the following way:

load("data.Rda")

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...