Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert RDA to csv

Tags:

r

I need to convert an rda file to csv. I've tried to load it in R , but I get the following error:

In readChar(con, 5L, useBytes = TRUE) :
  cannot open compressed file file 'data/matrix.rda', probable reason 'No such file or directory'

Here is a link to rda file (http://elisacarli.altervista.org/matrix.rda)

Thanks in advance for any suggestion

like image 377
elisacarli21 Avatar asked Dec 20 '10 05:12

elisacarli21


2 Answers

for starters, if your data is at that url, you needs to open a connection to the url and then load the .rda file:

con <- url('http://elisacarli.altervista.org/matrix.rda')
load(con)
close(con)

if you have the file on your computer, then just:

load('[full path to file]/matrix.rda')

this should create and object called 'matrix', see what is in it by typing:

matrix

then you would use this function:

write.csv(matrix,file="mysavefile.csv")
like image 184
Dr Nick Engerer Avatar answered Oct 23 '22 11:10

Dr Nick Engerer


This appears to be an issue of not having the object you are trying to write out to your csv in your working environment. Did you load your .RDA file first? I was able to load your .RDA file into my R session and write it out the LDH.aap.ave object with write.csv() with no apparent problems.

I recommend you check:

  1. What is in your current working environment? Check with ls(). Presumably, the contents of your .RDA file will not be in here. For cleanliness, maybe you want to clear your working environment first and start fresh? rm(list=ls()) will do the trick for you there.
  2. Your current working directory with getwd()
  3. The location of your .RDA file
  4. Navigate to the appropriate directory if needed with setwd()
  5. Use load("my.RDA")
  6. Check the objects in your current working environment with ls(). I see one object in the attached .RDA file named "LDH.aap.ave"
  7. You can check the structure of that object to make sure it was read in properly. head(), str(), summary() are your friends here.
  8. Write our LDH.aap.ave with write.csv(LDH.aap-ave, file = "myFileName.csv")
like image 10
Chase Avatar answered Oct 23 '22 09:10

Chase