I've got a netCDF data file.The file can be downloaded at:
http://www.nodc.noaa.gov/OC5/WOA09/pr_woa09.html
It's the one called WOA09 netCDF version.
I want to use only climatology data (variable 4) and the first depth range [ , ,1] so I've used the code below so far in R. In now want to have the subset called MyData in RData format.
I want to convert it to RData to be able to play around with it in R. I haven't found anything on the internet about doing this, is it even possible? How?
Thank you so much if you can help! And let me know if I haven't given enough info .
library(ncdf)
MyFile<-open.ncdf("/home/et1211/wspd.mean.nc")
MyFile$var[[4]]->var4
MyData<-get.var.ncdf(MyFile,var4)
MyData<-MyData[,,1]
It's simple. You just save the object from R and use .RData as extension:
save(MyData, file="myNCDFdata.RData")
Or else you can read the ncdf data to an empty workspace, do whatever transformations you need, and then quit R and click ok to save workspace.
Related
I define a DataFrame named data and want to write it into .csv file. I used writetable("result_data.csv", data) but it doesn't work.
This is the dataframe
error details
To write a data frame to a disk you should use the CSV.jl package like this (also make sure that you have write right to the directory you want to save the file on Juliabox):
using CSV
CSV.write("result_data.csv", data)
If this fails then please report back in the comment I will investigate it further.
I am trying to find out how I can see the data within a dataset with a .RData extension.
I tried view(), it gave me one object present in the dataset but I know that this dataset is a large dataset with over 300MB size and consists of a very large number of names list. I need to view all of the contents of it and have been unsuccessful so far.
Should I convert it into a CSV instead in order to view all of the contents? If yes, how can I do that using RStudio?
The cross-platform function is View. (Caps are discriminatory in R.) If you did:
obj <- load("filename.Rdata") # assuming a file exist in your working directory
Then type:
obj
You should see a print-listing of the character representations of the objects created (or possibly overwritten) in your global environment. The Rstudio aspect of this question would not affect the result.
I have received an .rdata file with what I think should be a list of co-ordinates (x,y) and their corresponding gray value; however, I do not know exactly the data type/format within the .rdata file. Is there a way for me to read these data without R? I do not have access to R. I have Excel and Matlab on a Mac. Please help. Unfortunately, I am not allowed to pass on the data (my Googling tells me someone familiar with R can export the data into a text of csv file easily).
Thank you in advance.
I downloaded R, read the .rdata in using load() and saved it out again using write.csv().
I want to export a dataset in the MASS package to SPSS for further investigation. I'm looking for the EuStockMarkets data set in the package.
As described in http://www.statmethods.net/input/exportingdata.html, I did:
library(foreign)
write.foreign(EuStockMarkets, "c:/mydata.txt", "c:/mydata.sps", package="SPSS")
I got a text file but the sps file is not a valid SPSS file. I'm really looking for a way to export the dataset to something that a SPSS can open.
As Thomas has mentioned in the comments, write.foreign doesn't generate native SPSS datafiles (.sav). What it does generate is the data in a comma delimited format (the .txt file) and a basic syntax file for reading that data into SPSS (the .sps file). The EuStockMarkets data object class is multivariate time series (mts) so when it's exported the metadata is lost and the resulting .sps file, lacking variable names, throws an error when you try to run it in SPSS. To get around this you can export it as a data frame instead:
write.foreign(as.data.frame(EuStockMarkets), "c:/mydata.txt", "c:/mydata.sps", package="SPSS")
Now you just need to open mydata.sps as a syntax file (NOT as a datafile) in SPSS and run it to read in the datafile.
Rather than exporting it, use the STATS GET R extension command. It will take a specified data frame from an R workspace/dataset and convert it into a Statistics dataset. You need the R Essentials for Statistics and the extension command, which are available via the SPSS Community site (www.ibm.com/developerworks/spssdevcentral)
I'm not trying to answer a question that has been answered. I just think there is something else to complement for other users looking for this.
On your SPSS window, you just need to find the first line of code and edit it. It should be something like this:
"file-name.txt"
You need to find the folder path where you're keeping your file:
"C:\Users\DELL\Google Drive\Folder-With-Your-File"
Then you just need to add this path to your file's name:
"C:\Users\DELL\Google Drive\Folder-With-Your-File\file-name.txt"
Otherwise SPSS will not recognize the .txt file.
Sorry if I'm repeating some information here, I just wanted to make it easier to understand.
I suppose that EuStockMarkets is a (labelled) data frame.
This should work and even keep the variable and value labels:
require(sjlabelled)
write_spss(EuStockMarkets, "mydata.sav")
Or you try rio:
rio::export(EuStockMarkets, "mydata.sav")
How can I read and write the following file using R ?
https://www.dropbox.com/s/vlnrlxjs7f977zz/3B42_daily.2012.11.23.7.nc
In other words, I would like to read the "3B42_daily.2012.11.23.7.nc" file and write with the same structure that it is written.
Best regards
Package ncdf have functions to do this. You should also read other Q&A on this site tagged with netcdf and r.
Basically to read a netcdf file:
library(ncdf)
a <- open.ncdf('your/path/to/your/file.nc') #that opens a connection to the file
Then function get.var.ncdf helps you extract the data, variable by variable.
The process to write one is described in this Q&A.
The idea is to create dimensions first using dim.def.ncdf then the variables with var.def.ncdf and finally the file itself using create.ncdf.