dataframe from a netcdf file in R

17 Views Asked by At

I have this netcdf file and I want to extract some information in the form of a dataset.

library(RNetCDF)
cdf<-open.nc("file.nc)
print.nc(cdf)

After printing, I can see 4 dimensions and several variables:

dimensions:
    date = UNLIMITED ; // (80 currently)
    simulation = 10 ;
    height = 150 ;
    type = 4 ;
variables 
...

From all the variables I am only interested in variable_10. I tried to get a data frame by extracting the variable using :

var<-var.get.nc(cdf,"variable_10")
df<-data.frame(var=var)

Doing this will extract the variables and all the dimensions with no specific names to see what is what. I would like to get for example the values of variable 10 that are within all heights (1:150), only type (2), all simulations (1:10), and within a certain date (20:30). I tried using cdf[1:150,2,1:10,20:30] but it will pull data but I do not know what data it is because I am not specifying in the variable. Is there an easy way to extract that data and convert it into a data frame with names in the columns that correspond to their value?

I tired searching for the information but could not find something that would help me

Thank you for your attention

0

There are 0 best solutions below