1

I want use the function "filled.contour", but my data file are ncdf4 file.

how to convert ncdf4 file to data.frame in R?

Some advice?

thanks

Ana Alicia
  • 11
  • 2
  • 2
    Hi Ana, welcome to StackOverflow. Please can you post what you have tried and found so far? A quick Google suggests there is some information available on this http://geog.uoregon.edu/bartlein/courses/geog490/week04-netCDF.html does that cover your use case? – Harry Mar 03 '18 at 00:09
  • See also [`rasterVis`](https://oscarperpinan.github.io/rastervis/) – Tung Mar 03 '18 at 03:52

1 Answers1

1

Because a NetCDF file can contain objects of many different dimensions, it is not a straightforward conversion. If you know the names of the variable you want to get out of the file you can do it like this:

library(ncdf4) nc<-nc_open("filename") ncvar_get(nc,varid= "variableNameInFile" ) nc_close(nc)

If you dont know the names of the attributes in your file you can use this to obtain them:

library(ncdf4) nc<-nc_open("filename") var.idNames<-names(nc$var) nc_close(nc)

Once you extract the individual variables you can just put them into a dataframe (data.frame()) if they are the same dimensions.

Hope this Helps! (and don't forget to close your file when you're done)

CStackUser
  • 11
  • 1