Rename data frame

I have a data.frame with name df. I would like to save it in a file with a better name. I would like to be able to do this:

df = ..., "gdp_2001_2014") # Now the data.frame has a new name and can be used as normal: gdp_2001_2014$y = 0 # And it can be saved with a nice name: save(gdp_2001_2014, file=".\\datafile.Rdata")

The name is important of the following reason: when you load data the name follows automatically:

load(".\\datafile.Rdata") summary(gdp_2001_2014)


## to re-name the data frame gdp_2001_2014 <- df ## remove data frame 'df' rm(df) ## write new data frame to file write.table(gdp_2001_2014, file = "yourPath.Rdata")

Depending on the data, you could also use write.csv or writeLines and others.


you can do it in 1 call

write.csv(df,file="gdp_2001_2014.csv",row.names=FALSE) #row.names=FALSE if you don't want the row index

人吐槽 人点赞



用户名: 密码:
验证码: 匿名发表


查看评论:Rename data frame