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 = ... rename.data.frame(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:
## 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
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