[R] saving and reading csv and rda files

Alok Bohara, PhD bohara at unm.edu
Mon Aug 27 16:56:50 CEST 2012


Hi:

I am trying to understand the link between ".csv" and  ".rda" files.    
Is there any easy to follow tutorial on this?

(I could do some of the operations below, but I got lost in the details.)

1.  Reading .rda file ?

data <- load("profit.rda")         # supposed to have four variable --y 
x1 x2 state_name

--how do I find out about the variable names,
--take the log of y and x1
--extract y and calculate mean etc..

(I want to use it in lm regression lny = f(lnx1,x2))

****************

2. How could I save this profit.rda file as a csv file  with the 
variable names attached?
I tried doing this:

profit_data <- load("profit.rda")

#Could I do this?
write.csv(profit_data, file="profit.csv", col.names=TRUE)
data2 <- read.csv("profit.csv", head = TRUE)

# saving .rda file without the header?
write.csv(profit_data, file="profit2.csv", col.names=FALSE)

***********

3. Creating a .rda file  from a csv file  using the save command

data2 <- read.csv("poverty.csv", head = T, sep = ",")   # poverty.csv 
file has 4 variables -- Q L K  country_name
save(data2, file="poverty.rda")

--How do I  attach names from the csv file to this .rda file?



Best,
Alok Bohara
UNM




More information about the R-help mailing list